/** * Tests whether the page entity config schema is valid. */ public function testValidPageConfigSchema() { $id = 'node_view'; /** @var \Drupal\page_manager\PageInterface $page */ $page = Page::load($id); // Add an access condition. $page->addAccessCondition(['id' => 'node_type', 'bundles' => ['article' => 'article'], 'negate' => TRUE, 'context_mapping' => ['node' => 'node']]); $page->save(); $page_variant_id = 'block_page'; // Add a block variant. $page_variant = PageVariant::create(['variant' => 'block_display', 'id' => $page_variant_id, 'label' => 'Block page', 'page' => $page->id()]); $page_variant->save(); $page->addVariant($page_variant); /** @var \Drupal\page_manager\Plugin\DisplayVariant\PageBlockDisplayVariant $variant_plugin */ $variant_plugin = $page_variant->getVariantPlugin(); // Add a selection condition. $page_variant->addSelectionCondition(['id' => 'node_type', 'bundles' => ['page' => 'page'], 'context_mapping' => ['node' => 'node']]); // Add a block. $variant_plugin->addBlock(['id' => 'entity_view:node', 'label' => 'View the node', 'provider' => 'page_manager', 'label_display' => 'visible', 'view_mode' => 'default']); $page_variant->save(); $page_config = \Drupal::config("page_manager.page.{$id}"); $this->assertSame($page_config->get('id'), $id); $variant_config = \Drupal::config("page_manager.page_variant.{$page_variant_id}"); $this->assertSame($variant_config->get('id'), $page_variant_id); $this->assertConfigSchema(\Drupal::service('config.typed'), $page_config->getName(), $page_config->get()); $this->assertConfigSchema(\Drupal::service('config.typed'), $variant_config->getName(), $variant_config->get()); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); // Remove the 'access content' permission from anonymous and auth users. Role::load(RoleInterface::ANONYMOUS_ID)->revokePermission('access content')->save(); Role::load(RoleInterface::AUTHENTICATED_ID)->revokePermission('access content')->save(); $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']); $this->drupalCreateContentType(['type' => 'page', 'name' => 'Page']); $this->drupalPlaceBlock('page_title_block'); $this->page = Page::load('node_view'); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->drupalPlaceBlock('local_tasks_block'); $this->drupalPlaceBlock('local_actions_block'); $this->drupalPlaceBlock('system_branding_block'); $this->drupalPlaceBlock('page_title_block'); \Drupal::service('theme_handler')->install(['bartik', 'classy']); $this->config('system.theme')->set('admin', 'classy')->save(); $this->drupalLogin($this->drupalCreateUser(['administer pages', 'access administration pages', 'view the administration theme'])); // Remove the default node_view page to start with a clean UI. Page::load('node_view')->delete(); }
/** * Gets the page this variant is on. * * @return \Drupal\page_manager\Entity\Page */ protected function getPage() { if (!$this->page) { throw new \UnexpectedValueException('The page variant has no associated page'); } return Page::load($this->page); }
/** * Tests that a node bundle condition controls the node view page. */ public function testAdmin() { // Create two nodes, and view their pages. $node1 = $this->drupalCreateNode(['type' => 'page']); $node2 = $this->drupalCreateNode(['type' => 'article']); $node3 = $this->drupalCreateNode(['type' => 'article']); $this->drupalGet('node/' . $node1->id()); $this->assertResponse(200); $this->assertText($node1->label()); $this->assertTitle($node1->label() . ' | Drupal'); $this->drupalGet('node/' . $node2->id()); $this->assertResponse(200); $this->assertCacheTag('page_manager_route_name:entity.node.canonical'); $this->assertText($node2->label()); $this->assertTitle($node2->label() . ' | Drupal'); // Create a new page entity to take over node pages. $edit = ['label' => 'Node View', 'id' => 'node_view', 'path' => 'node/%']; $this->drupalPostForm('admin/structure/page_manager/add', $edit, 'Save'); // Create a new variant to always return 404. $edit = ['id' => 'http_status_code', 'variant_settings[status_code]' => 404]; $this->drupalPostForm('admin/structure/page_manager/manage/node_view/add/http_status_code', $edit, 'Save'); $this->drupalGet('node/' . $node1->id()); $this->assertResponse(404); $this->assertCacheTag('page_manager_route_name:entity.node.canonical'); $this->assertNoText($node1->label()); $this->drupalGet('node/' . $node2->id()); $this->assertResponse(404); $this->assertNoText($node2->label()); // Add a new variant. $this->drupalGet('admin/structure/page_manager/manage/node_view'); $this->clickLink('Add new variant'); $this->clickLink('Block page'); $edit = ['id' => 'block_page_first', 'label' => 'First']; $this->drupalPostForm(NULL, $edit, 'Save'); // Add the entity view block. $this->clickLink('Add new block'); $this->clickLink('Entity view (Content)'); $edit = ['region' => 'top', 'settings[label_display]' => FALSE]; $this->drupalPostForm(NULL, $edit, 'Add block'); // Add a node bundle condition for articles. $this->clickLink('Add new selection condition'); $this->clickLink('Node Bundle'); $edit = ['condition[bundles][article]' => TRUE]; $this->drupalPostForm(NULL, $edit, 'Add selection condition'); // Set the page title to the node title. $edit = ['variant_settings[page_title]' => '[node:title]']; $this->drupalPostForm(NULL, $edit, 'Save'); /** @var \Drupal\page_manager\PageInterface $page */ $page = Page::load('node_view'); foreach ($page->getVariants() as $block_variant_uuid => $block_variant) { if ($block_variant->label() == 'First') { break; } } // Set the weight of the block_page variant to -10. $edit = ['variants[' . $block_variant_uuid . '][weight]' => -10]; $this->drupalPostForm(NULL, $edit, 'Save'); // The page node will 404, but the article node will display the variant. $this->drupalGet('node/' . $node1->id()); $this->assertResponse(404); $this->assertNoText($node1->label()); $this->drupalGet('node/' . $node2->id()); $this->assertResponse(200); $this->assertTitle($node2->label() . ' | Drupal'); $this->assertText($node2->body->value); // Test cacheability metadata. $this->drupalGet('node/' . $node3->id()); $this->assertNoText($node2->label()); // Ensure this doesn't affect the /node/add page. $this->drupalGet('node/add'); $this->assertResponse(200); }
/** * Finds a display variant based on its page and display variant label. * * @param string $page_id * The ID of the page entity. * @param string $display_variant_label * The label of the display variant. * * @return \Drupal\Core\Display\VariantInterface|null * Either a display variant, or NULL. */ protected function findDisplayVariantByLabel($page_id, $display_variant_label) { if ($page = Page::load($page_id)) { /** @var $page \Drupal\page_manager\PageInterface */ foreach ($page->getVariants() as $display_variant) { if ($display_variant->label() == $display_variant_label) { return $display_variant; } } } return NULL; }
/** * Tests the parameters UI. */ public function testParameters() { $this->drupalGet('admin/structure/page_manager'); $this->clickLink('Add page'); $edit = ['id' => 'foo', 'label' => 'Foo', 'path' => '/foo/{user}']; $this->drupalPostForm(NULL, $edit, 'Save'); $this->assertText('No context assigned'); $this->clickLink('Edit'); $this->drupalPostForm(NULL, ['type' => 'entity:user'], 'Update parameter'); $this->assertNoText('No context assigned'); $this->assertText('entity:user'); $parameters = Page::load('foo')->getParameters(); $this->assertIdentical(['user' => ['machine_name' => 'user', 'type' => 'entity:user', 'label' => 'User']], $parameters); }