Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form['label'] = ['#type' => 'textfield', '#title' => $this->t('Label'), '#description' => $this->t('The label for this page.'), '#default_value' => $this->entity->label(), '#required' => TRUE, '#maxlength' => '255'];
     $form['id'] = ['#type' => 'machine_name', '#default_value' => $this->entity->id(), '#disabled' => !$this->entity->isNew(), '#maxlength' => 64, '#required' => TRUE, '#machine_name' => ['exists' => [$this, 'exists']]];
     $form['path'] = ['#type' => 'textfield', '#title' => $this->t('Path'), '#maxlength' => 255, '#default_value' => $this->entity->getPath(), '#required' => TRUE, '#element_validate' => [[$this, 'validatePath']]];
     return parent::form($form, $form_state);
 }
Esempio n. 2
0
 /**
  * Tests that a user role condition controls the node view page.
  */
 public function testUserRoleAccessCondition()
 {
     $node1 = $this->drupalCreateNode(['type' => 'page']);
     $node2 = $this->drupalCreateNode(['type' => 'article']);
     $this->drupalLogin($this->drupalCreateUser(['access content']));
     $this->drupalGet('node/' . $node1->id());
     $this->assertResponse(200);
     $this->assertText($node1->label());
     $this->assertTitle($node1->label() . ' | Drupal');
     // Add a variant and an access condition.
     /** @var \Drupal\page_manager\Entity\PageVariant $page_variant */
     $page_variant = PageVariant::create(['variant' => 'block_display', 'id' => 'block_page', 'label' => 'Block page', 'page' => $this->page->id()]);
     $page_variant->getVariantPlugin()->setConfiguration(['page_title' => 'The overridden page']);
     $page_variant->save();
     $this->page->addAccessCondition(['id' => 'user_role', 'roles' => [RoleInterface::AUTHENTICATED_ID => RoleInterface::AUTHENTICATED_ID], 'context_mapping' => ['user' => 'current_user']]);
     $this->page->addAccessCondition(['id' => 'node_type', 'bundles' => ['page' => 'page'], 'context_mapping' => ['node' => 'node']]);
     $this->page->save();
     $this->triggerRouterRebuild();
     $this->drupalLogout();
     $this->drupalGet('node/' . $node1->id());
     $this->assertResponse(403);
     $this->assertNoText($node1->label());
     $this->assertTitle('Access denied | Drupal');
     $this->drupalLogin($this->drupalCreateUser());
     $this->drupalGet('node/' . $node1->id());
     $this->assertResponse(403);
     $this->assertNoText($node1->label());
     $this->assertTitle('Access denied | Drupal');
     $this->drupalLogin($this->drupalCreateUser(['access content']));
     $this->drupalGet('node/' . $node1->id());
     $this->assertResponse(200);
     $this->assertNoText($node1->label());
     $this->assertTitle('The overridden page | Drupal');
     $this->drupalGet('node/' . $node2->id());
     $this->assertResponse(403);
     $this->assertNoText($node2->label());
     $this->assertTitle('Access denied | Drupal');
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $settings = (new FormState())->setValues($form_state->getValue('settings'));
     // Call the plugin submit handler.
     $this->block->submitConfigurationForm($form, $settings);
     // Update the original form values.
     $form_state->setValue('settings', $settings->getValues());
     if ($this->block instanceof ContextAwarePluginInterface) {
         $this->block->setContextMapping($form_state->getValue('context_mapping', []));
     }
     $this->displayVariant->updateBlock($this->block->getConfiguration()['uuid'], ['region' => $form_state->getValue('region')]);
     $this->page->save();
     $form_state->setRedirect('page_manager.display_variant_edit', ['page' => $this->page->id(), 'display_variant_id' => $this->displayVariant->id()]);
 }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, array &$form_state)
 {
     // Allow the page variant to submit the form.
     $plugin_values = array('values' => &$form_state['values']['plugin']);
     $this->layoutRegion->submitConfigurationForm($form, $plugin_values);
     $this->pageVariant->updateLayoutRegion($this->layoutRegion->id(), array('label' => $this->layoutRegion->label(), 'parent' => $this->layoutRegion->getParentRegionId()));
     $this->page->save();
     if ($this->getRequest()->isXmlHttpRequest()) {
         $response = new AjaxResponse();
         $response->addCommand(new CloseDialogCommand());
         if ($this->getFormId() === 'layout_layout_region_add_form') {
             $response->addCommand(new LayoutReload($this->pageVariant));
         } else {
             $response->addCommand(new LayoutRegionReload($this->pageVariant, $this->layoutRegion));
         }
         $form_state['response'] = $response;
         return $response;
     }
     $form_state['redirect_route'] = new Url('page_manager.display_variant_edit', array('page' => $this->page->id(), 'display_variant_id' => $this->pageVariant->id()));
 }
 /**
  * Build the page variant entity add form.
  *
  * @param \Drupal\page_manager\PageInterface $page
  *   The page this page variant belongs to.
  * @param string $variant_plugin_id
  *   The variant plugin ID.
  *
  * @return array
  *   The page variant entity add form.
  */
 public function addPageVariantEntityForm(PageInterface $page, $variant_plugin_id)
 {
     // Create a page variant entity.
     $entity = $this->entityTypeManager()->getStorage('page_variant')->create(['page' => $page->id(), 'variant' => $variant_plugin_id]);
     return $this->entityFormBuilder()->getForm($entity, 'add');
 }
Esempio n. 6
0
 /**
  * Presents a list of blocks to add to the display variant.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The current request.
  * @param \Drupal\page_manager\PageInterface $page
  *   The page entity.
  * @param string $display_variant_id
  *   The display variant ID.
  *
  * @return array
  *   The block selection page.
  */
 public function selectBlock(Request $request, PageInterface $page, $display_variant_id)
 {
     // Add a section containing the available blocks to be added to the variant.
     $build = ['#type' => 'container', '#attached' => ['library' => ['core/drupal.ajax']]];
     $available_plugins = $this->blockManager->getDefinitionsForContexts($page->getContexts());
     foreach ($available_plugins as $plugin_id => $plugin_definition) {
         // Make a section for each region.
         $category = SafeMarkup::checkPlain($plugin_definition['category']);
         $category_key = 'category-' . $category;
         if (!isset($build[$category_key])) {
             $build[$category_key] = ['#type' => 'fieldgroup', '#title' => $category, 'content' => ['#theme' => 'links']];
         }
         // Add a link for each available block within each region.
         $build[$category_key]['content']['#links'][$plugin_id] = ['title' => $plugin_definition['admin_label'], 'url' => Url::fromRoute('page_manager.display_variant_add_block', ['page' => $page->id(), 'display_variant_id' => $display_variant_id, 'block_id' => $plugin_id, 'region' => $request->query->get('region')]), 'attributes' => ['class' => ['use-ajax'], 'data-dialog-type' => 'modal', 'data-dialog-options' => Json::encode(['width' => 'auto'])]];
     }
     return $build;
 }
 /**
  * Presents a list of blocks to add to the page variant.
  *
  * @param \Drupal\page_manager\PageInterface $layout
  *   The page entity.
  * @param string $layout_region_id
  *   The page variant ID.
  *
  * @return array
  *   The block selection page.
  */
 public function selectRegion(PageInterface $page, $page_variant_id, $layout_region_id = NULL)
 {
     // Add a section containing the available blocks to be added to the variant.
     $form = array('#type' => 'container', '#attached' => array('library' => array('core/drupal.ajax')));
     // Get the available layout region plugins
     $definitions = $this->layoutRegionManager->getDefinitions();
     foreach ($definitions as $plugin_id => $plugin_definition) {
         $plugin = $this->layoutRegionManager->createInstance($plugin_id, array());
         if (is_subclass_of($plugin, 'Drupal\\layout\\Plugin\\LayoutRegion\\LayoutConfigurableRegionInterface')) {
             $category = isset($plugin_definition['category']) ? String::checkPlain($plugin_definition['category']) : '';
             $category_key = 'category-' . $category;
             if (!isset($form['place_regions']['list'][$category_key])) {
                 $form['place_regions']['list'][$category_key] = array('#type' => 'details', '#title' => $category, '#open' => TRUE, 'content' => array('#theme' => 'links', '#links' => array(), '#attributes' => array('class' => array('block-list'))));
             }
             $label = isset($plugin_definition['admin_label']) ? $plugin_definition['admin_label'] : isset($plugin_definition['label']) ? $plugin_definition['label'] : $plugin_definition['id'];
             $form['place_regions']['list'][$category_key]['content']['#links'][$plugin_id] = array('title' => $label, 'href' => '/admin/structure/page_manager/manage/' . $page->id() . '/manage/' . $page_variant_id . '/layout/' . $layout_region_id . '/region/' . $plugin_id . '/add', 'attributes' => array('class' => array('use-ajax', 'block-filter-text-source'), 'data-accepts' => 'application/vnd.drupal-modal', 'data-dialog-options' => Json::encode(array('width' => 700))));
         }
     }
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function getCancelUrl()
 {
     return new Url('page_manager.display_variant_edit', ['page' => $this->page->id(), 'display_variant_id' => $this->displayVariant->id()]);
 }
Esempio n. 9
0
 /**
  * {@inheritdoc}
  */
 public function getCancelRoute()
 {
     return new Url('page_manager.display_variant_edit', array('page' => $this->page->id(), 'page_variant_id' => $this->pageVariant->id()));
 }