Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     $default = $this->entity->getMenuName() . ':' . $this->entity->getParentId();
     $id = $this->entity->isNew() ? '' : $this->entity->getPluginId();
     $form['menu_parent'] = $this->menuParentSelector->parentSelectElement($default, $id);
     $form['menu_parent']['#weight'] = 10;
     $form['menu_parent']['#title'] = $this->t('Parent link');
     $form['menu_parent']['#description'] = $this->t('The maximum depth for a link and all its children is fixed. Some menu links may not be available as parents if selecting them would exceed this limit.');
     $form['menu_parent']['#attributes']['class'][] = 'menu-title-select';
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     // We always show the internal path here.
     /** @var \Drupal\Core\Url $url */
     $url = $this->getEntity()->getUrlObject();
     if ($url->isExternal()) {
         $default_value = $url->toString();
     } elseif ($url->getRouteName() == '<front>') {
         // The default route for new entities is <front>, but we just want an
         // empty form field.
         $default_value = $this->getEntity()->isNew() ? '' : '<front>';
     } else {
         // @todo Url::getInternalPath() calls UrlGenerator::getPathFromRoute()
         // which need a replacement since it is deprecated.
         // https://www.drupal.org/node/2307061
         $default_value = $url->getInternalPath();
         // @todo Add a helper method to Url to render just the query string and
         // fragment. https://www.drupal.org/node/2305013
         $options = $url->getOptions();
         if (isset($options['query'])) {
             $default_value .= $options['query'] ? '?' . UrlHelper::buildQuery($options['query']) : '';
         }
         if (isset($options['fragment']) && $options['fragment'] !== '') {
             $default_value .= '#' . $options['fragment'];
         }
     }
     $form['url'] = array('#title' => $this->t('Link path'), '#type' => 'textfield', '#description' => $this->t('The path for this menu link. This can be an internal Drupal path such as %add-node or an external URL such as %drupal. Enter %front to link to the front page.', array('%front' => '<front>', '%add-node' => 'node/add', '%drupal' => 'http://drupal.org')), '#default_value' => $default_value, '#required' => TRUE, '#weight' => -2);
     $language_configuration = $this->moduleHandler->invoke('language', 'get_default_configuration', array('menu_link_content', 'menu_link_content'));
     if ($this->entity->isNew()) {
         $default_language = isset($language_configuration['langcode']) ? $language_configuration['langcode'] : $this->languageManager->getDefaultLanguage()->getId();
     } else {
         $default_language = $this->entity->getUntranslated()->language()->getId();
     }
     $form['langcode'] = array('#title' => t('Language'), '#type' => 'language_select', '#default_value' => $default_language, '#languages' => Language::STATE_ALL, '#access' => !empty($language_configuration['language_show']));
     $form['enabled'] = array('#type' => 'checkbox', '#title' => $this->t('Enable menu link'), '#description' => $this->t('Menu links that are not enabled will not be listed in any menu.'), '#default_value' => !$this->entity->isHidden(), '#weight' => 0);
     $default = $this->entity->getMenuName() . ':' . $this->entity->getParentId();
     $form['menu_parent'] = $this->menuParentSelector->parentSelectElement($default, $this->entity->getPluginId());
     $form['menu_parent']['#weight'] = 10;
     $form['menu_parent']['#title'] = $this->t('Parent link');
     $form['menu_parent']['#description'] = $this->t('The maximum depth for a link and all its children is fixed. Some menu links may not be available as parents if selecting them would exceed this limit.');
     $form['menu_parent']['#attributes']['class'][] = 'menu-title-select';
     return $form;
 }