예제 #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);
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $this->displayVariant->removeBlock($this->block->getConfiguration()['uuid']);
     $this->page->save();
     drupal_set_message($this->t('The block %label has been removed.', ['%label' => $this->block->label()]));
     $form_state->setRedirectUrl($this->getCancelUrl());
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $this->page->removeVariant($this->displayVariant->id());
     $this->page->save();
     drupal_set_message($this->t('The display variant %name has been removed.', ['%name' => $this->displayVariant->label()]));
     $form_state->setRedirectUrl($this->getCancelUrl());
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     drupal_set_message($this->t('The static context %label has been removed.', ['%label' => $this->page->getStaticContext($this->staticContext)['label']]));
     $this->page->removeStaticContext($this->staticContext);
     $this->page->save();
     $form_state->setRedirectUrl($this->getCancelUrl());
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $this->page->removeAccessCondition($this->accessCondition->getConfiguration()['uuid']);
     $this->page->save();
     drupal_set_message($this->t('The access condition %name has been removed.', ['%name' => $this->accessCondition->getPluginDefinition()['label']]));
     $form_state->setRedirectUrl($this->getCancelUrl());
 }
예제 #6
0
 /**
  * @covers ::selectDisplayVariant
  */
 public function testSelectDisplayVariant()
 {
     $display_variant1 = $this->prophesize(VariantInterface::class);
     $display_variant1->access()->willReturn(FALSE);
     $display_variant2 = $this->prophesize(PageAwareVariantInterface::class);
     $display_variant2->access()->willReturn(TRUE);
     $display_variant2->setExecutable($this->exectuable)->willReturn($display_variant2->reveal());
     $this->page->getVariants()->willReturn(['variant1' => $display_variant1->reveal(), 'variant2' => $display_variant2->reveal()]);
     $this->assertSame($display_variant2->reveal(), $this->exectuable->selectDisplayVariant());
 }
예제 #7
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->typedDataManager = $this->prophesize(TypedDataManager::class);
     $container = new ContainerBuilder();
     $container->set('string_translation', $this->getStringTranslationStub());
     $container->set('typed_data_manager', $this->typedDataManager->reveal());
     \Drupal::setContainer($container);
     $this->page = $this->prophesize(PageInterface::class);
     $this->event = new PageManagerContextEvent($this->page->reveal());
 }
예제 #8
0
 /**
  * Gets the displayable path of a page entity.
  *
  * @param \Drupal\page_manager\PageInterface $entity
  *   The page entity.
  *
  * @return array|string
  *   The value of the path.
  */
 protected function getPath(PageInterface $entity)
 {
     // If the page is enabled and not dynamic, show the path as a link,
     // otherwise as plain text.
     $path = $entity->getPath();
     if ($entity->status() && strpos($path, '%') === FALSE) {
         return ['data' => ['#type' => 'link', '#url' => Url::fromUserInput(rtrim($path, '/')), '#title' => $path]];
     } else {
         return $path;
     }
 }
 /**
  * @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);
 }
예제 #10
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     parent::submitForm($form, $form_state);
     $configuration = $this->condition->getConfiguration();
     // If this access condition is new, add it to the page.
     if (!isset($configuration['uuid'])) {
         $this->page->addAccessCondition($configuration);
     }
     // Save the page entity.
     $this->page->save();
     $form_state->setRedirectUrl($this->page->toUrl('edit-form'));
 }
예제 #11
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;
 }
예제 #12
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, PageInterface $page = NULL, $display_variant_id = NULL)
 {
     $this->page = $page;
     $this->displayVariant = $this->prepareDisplayVariant($display_variant_id);
     if ($this->displayVariant instanceof PageAwareVariantInterface) {
         $this->displayVariant->setExecutable($this->page->getExecutable());
     }
     // Allow the display variant to add to the form.
     $form['display_variant'] = $this->displayVariant->buildConfigurationForm([], $form_state);
     $form['display_variant']['#tree'] = TRUE;
     $form['actions'] = ['#type' => 'actions'];
     $form['actions']['submit'] = ['#type' => 'submit', '#value' => $this->submitText(), '#button_type' => 'primary'];
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function handle(Request $request, PageInterface $page = NULL, $page_variant_id = NULL)
 {
     // @todo: this is clearly not restful - but let's get this on the road
     switch ($request->getMethod()) {
         case 'PUT':
             $page_variant = $page->getVariant($page_variant_id);
             $page_variant->init($page->getExecutable());
             if (!$page_variant) {
                 throw BadRequestHttpException('Invalid page variant id provided');
             }
             $payload = $request->getContent();
             $data = json_decode($payload, TRUE);
             return $this->handlePut($page, $page_variant, $data);
             break;
         default:
             throw new BadRequestHttpException('Invalid HTTP method, currently only PUT supported');
     }
 }
예제 #14
0
 /**
  * {@inheritdoc}
  */
 public function selectDisplayVariant()
 {
     if (!$this->selectedDisplayVariant) {
         foreach ($this->page->getVariants() as $display_variant) {
             if ($display_variant instanceof ContextAwareVariantInterface) {
                 $display_variant->setContexts($this->getContexts());
             }
             if ($display_variant->access()) {
                 if ($display_variant instanceof PageAwareVariantInterface) {
                     $display_variant->setExecutable($this);
                 }
                 $this->selectedDisplayVariant = $display_variant;
                 break;
             }
         }
     }
     return $this->selectedDisplayVariant;
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, array &$form_state, PageInterface $page = NULL, $page_variant_id = NULL, $layout_region_id = NULL, $block_id = NULL)
 {
     $this->page = $page;
     $this->displayVariant = $this->page->getVariant($page_variant_id);
     $this->displayVariant->setExecutable($page->getExecutable());
     $this->layoutRegion = $this->displayVariant->getLayoutRegion($layout_region_id);
     $this->block = $this->prepareBlock($block_id);
     $form['#tree'] = TRUE;
     $form['settings'] = $this->block->buildConfigurationForm(array(), $form_state);
     $form['settings']['id'] = array('#type' => 'value', '#value' => $this->block->getPluginId());
     // @note: we removed the region widget as it is implicit in URL.
     if ($this->block instanceof ContextAwarePluginInterface) {
         $form['context_assignments'] = $this->addContextAssignmentElement($this->block, $this->displayVariant->getContexts());
     }
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->submitText(), '#button_type' => 'primary');
     if ($this->getRequest()->isXmlHttpRequest()) {
         $form['actions']['submit']['#ajax'] = array('callback' => array($this, 'submitForm'));
     }
     return $form;
 }
예제 #16
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()]);
 }
예제 #18
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, array &$form_state)
 {
     $this->pageVariant->removeLayoutRegion($this->layoutRegion->id());
     $this->page->save();
     drupal_set_message($this->t('The layout region %name has been removed.', array('%name' => $this->layoutRegion->label())));
     if ($this->getRequest()->isXmlHttpRequest()) {
         $response = new AjaxResponse();
         $response->addCommand(new CloseDialogCommand());
         $response->addCommand(new LayoutReload($this->pageVariant));
         $form_state['response'] = $response;
         return $response;
     }
     $form_state['redirect_route'] = $this->getCancelRoute();
 }
예제 #19
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $name = $form_state->getValue('machine_name');
     $type = $form_state->getValue('type');
     if ($type === static::NO_CONTEXT_KEY) {
         $this->page->removeParameter($name);
         $label = NULL;
     } else {
         $label = $form_state->getValue('label');
         $this->page->setParameter($name, $type, $label);
     }
     $this->page->save();
     // Set the submission message.
     drupal_set_message($this->t('The %label parameter has been updated.', ['%label' => $label ?: $name]));
     $form_state->setRedirectUrl($this->page->toUrl('edit-form'));
 }
예제 #20
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()));
 }
 /**
  * Finds the overridden route name.
  *
  * @param \Drupal\page_manager\PageInterface $entity
  *   The page entity.
  * @param \Symfony\Component\Routing\RouteCollection $collection
  *   The route collection.
  *
  * @return string|null
  *   Either the route name if this is overriding an existing path, or NULL.
  */
 protected function findPageRouteName(PageInterface $entity, RouteCollection $collection)
 {
     // Get the stored page path.
     $path = $entity->getPath();
     // Loop through all existing routes to see if this is overriding a route.
     foreach ($collection->all() as $name => $collection_route) {
         // Find all paths which match the path of the current display.
         $route_path = $collection_route->getPath();
         $route_path_outline = RouteCompiler::getPatternOutline($route_path);
         // Match either the path or the outline, e.g., '/foo/{foo}' or '/foo/%'.
         if ($path === $route_path || $path === $route_path_outline) {
             // Return the overridden route name.
             return $name;
         }
     }
 }
 /**
  * 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');
 }
예제 #23
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]);
 }
예제 #24
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;
 }
예제 #25
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, PageInterface $page = NULL, $display_variant_id = NULL, $condition_id = NULL)
 {
     $this->displayVariant = $page->getVariant($display_variant_id);
     return parent::buildForm($form, $form_state, $page, $condition_id);
 }
 /**
  * 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;
 }
예제 #27
0
 /**
  * @covers ::getPage
  */
 public function testGetPage()
 {
     $this->assertSame($this->page->reveal(), $this->exectuable->getPage());
 }