/**
  * @covers ::getContexts
  * @covers ::removeStaticContext
  */
 public function testGetContextsAfterReset()
 {
     $this->contextMapper->getContextValues([])->willReturn([])->shouldBeCalledTimes(2);
     $this->page->getContexts()->willReturn([])->shouldBeCalledTimes(2);
     $expected = [];
     $contexts = $this->pageVariant->getContexts();
     $this->assertSame($expected, $contexts);
     $this->pageVariant->removeStaticContext('anything');
     $contexts = $this->pageVariant->getContexts();
     $this->assertSame($expected, $contexts);
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, PageInterface $page = NULL, $condition_id = NULL)
 {
     $this->page = $page;
     $this->condition = $this->prepareCondition($condition_id);
     $temporary = $form_state->getTemporary();
     $temporary['gathered_contexts'] = $this->page->getContexts();
     $form_state->setTemporary($temporary);
     // Allow the condition to add to the form.
     $form['condition'] = $this->condition->buildConfigurationForm([], $form_state);
     $form['condition']['#tree'] = TRUE;
     $form['actions'] = ['#type' => 'actions'];
     $form['actions']['submit'] = ['#type' => 'submit', '#value' => $this->submitButtonText(), '#button_type' => 'primary'];
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, PageInterface $page = NULL, $display_variant_id = NULL, $block_id = NULL)
 {
     $this->page = $page;
     $this->displayVariant = $page->getVariant($display_variant_id);
     $this->block = $this->prepareBlock($block_id);
     $form_state->set('display_variant_id', $display_variant_id);
     $form_state->set('block_id', $this->block->getConfiguration()['uuid']);
     $form['#tree'] = TRUE;
     $form['settings'] = $this->block->buildConfigurationForm([], $form_state);
     $form['settings']['id'] = ['#type' => 'value', '#value' => $this->block->getPluginId()];
     $form['region'] = ['#title' => $this->t('Region'), '#type' => 'select', '#options' => $this->displayVariant->getRegionNames(), '#default_value' => $this->displayVariant->getRegionAssignment($this->block->getConfiguration()['uuid']), '#required' => TRUE];
     if ($this->block instanceof ContextAwarePluginInterface) {
         $form['context_mapping'] = $this->addContextAssignmentElement($this->block, $this->page->getContexts());
     }
     $form['actions']['submit'] = ['#type' => 'submit', '#value' => $this->submitText(), '#button_type' => 'primary'];
     return $form;
 }
 /**
  * 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 selectBlock(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')));
     // Sort the plugins first by category, then by label.
     $plugins = $this->blockManager->getDefinitionsForContexts($page->getContexts());
     foreach ($plugins as $plugin_id => $plugin_definition) {
         $category = String::checkPlain($plugin_definition['category']);
         $category_key = 'category-' . $category;
         if (!isset($form['place_blocks']['list'][$category_key])) {
             $form['place_blocks']['list'][$category_key] = array('#type' => 'details', '#title' => $category, '#open' => TRUE, 'content' => array('#theme' => 'links', '#links' => array(), '#attributes' => array('class' => array('block-list'))));
         }
         $form['place_blocks']['list'][$category_key]['content']['#links'][$plugin_id] = array('title' => $plugin_definition['admin_label'], 'href' => '/admin/structure/page_manager/manage/' . $page->id() . '/manage/' . $page_variant_id . '/layout/' . $layout_region_id . '/block/' . $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;
 }
Пример #5
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, PageInterface $page = NULL, $condition_id = NULL)
 {
     $this->page = $page;
     return parent::buildForm($form, $form_state, $condition_id, $page->getContexts());
 }
 /**
  * Presents a list of access conditions to add to the page entity.
  *
  * @param \Drupal\page_manager\PageInterface $page
  *   The page entity.
  *
  * @return array
  *   The access condition selection page.
  */
 public function selectAccessCondition(PageInterface $page)
 {
     $build = ['#theme' => 'links', '#links' => []];
     $available_plugins = $this->conditionManager->getDefinitionsForContexts($page->getContexts());
     foreach ($available_plugins as $access_id => $access_condition) {
         $build['#links'][$access_id] = ['title' => $access_condition['label'], 'url' => Url::fromRoute('page_manager.access_condition_add', ['page' => $page->id(), 'condition_id' => $access_id]), 'attributes' => $this->getAjaxAttributes()];
     }
     return $build;
 }
Пример #7
0
 /**
  * Determines if a context with that name already exists.
  *
  * @param string $name
  *   The context name
  *
  * @return bool
  *   TRUE if the format exists, FALSE otherwise.
  */
 public function contextExists($name)
 {
     return isset($this->page->getContexts()[$name]);
 }
Пример #8
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;
 }