/** * {@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); }
/** * 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; } }
/** * 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; } } }