Commit 475a3c73 authored by catch's avatar catch
Browse files

Issue #2302085 by voleger, pooja saraah, Rishabh Vishwakarma, victoru: Keep...

Issue #2302085 by voleger, pooja saraah, Rishabh Vishwakarma, victoru: Keep MenuTreeStorage field definition in sync with MenuLinkManager
parent 25b8da7b
Loading
Loading
Loading
Loading
+50 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\Core\Menu;

/**
 * Provides base field definitions for an entity type.
 *
 * @package Drupal\Core\Menu
 */
trait MenuLinkFieldDefinitions {

  /**
   * Provides some default values for the definition of all menu link plugins.
   *
   * @var array
   */
  protected $defaults = [
    // (required) The name of the menu for this link.
    'menu_name' => 'tools',
    // (required) The name of the route this links to, unless it's external.
    'route_name' => '',
    // Parameters for route variables when generating a link.
    'route_parameters' => [],
    // The external URL if this link has one (required if route_name is empty).
    'url' => '',
    // The static title for the menu link. If this came from a YAML definition
    // or other safe source this may be a TranslatableMarkup object.
    'title' => '',
    // The description. If this came from a YAML definition or other safe source
    // this may be be a TranslatableMarkup object.
    'description' => '',
    // The plugin ID of the parent link (or NULL for a top-level link).
    'parent' => '',
    // The weight of the link.
    'weight' => 0,
    // The default link options.
    'options' => [],
    'expanded' => 0,
    'enabled' => 1,
    // The name of the module providing this link.
    'provider' => '',
    'metadata' => [],
    // Default class for local task implementations.
    'class' => 'Drupal\Core\Menu\MenuLinkDefault',
    'form_class' => 'Drupal\Core\Menu\Form\MenuLinkDefaultForm',
    // The plugin ID. Set by the plugin system based on the top-level YAML key.
    'id' => '',
  ];

}
+1 −40
Original line number Diff line number Diff line
@@ -17,46 +17,7 @@
 */
class MenuLinkManager implements MenuLinkManagerInterface {

  /**
   * Provides some default values for the definition of all menu link plugins.
   *
   * @todo Decide how to keep these field definitions in sync.
   *   https://www.drupal.org/node/2302085
   *
   * @var array
   */
  protected $defaults = [
    // (required) The name of the menu for this link.
    'menu_name' => 'tools',
    // (required) The name of the route this links to, unless it's external.
    'route_name' => '',
    // Parameters for route variables when generating a link.
    'route_parameters' => [],
    // The external URL if this link has one (required if route_name is empty).
    'url' => '',
    // The static title for the menu link. If this came from a YAML definition
    // or other safe source this may be a TranslatableMarkup object.
    'title' => '',
    // The description. If this came from a YAML definition or other safe source
    // this may be a TranslatableMarkup object.
    'description' => '',
    // The plugin ID of the parent link (or NULL for a top-level link).
    'parent' => '',
    // The weight of the link.
    'weight' => 0,
    // The default link options.
    'options' => [],
    'expanded' => 0,
    'enabled' => 1,
    // The name of the module providing this link.
    'provider' => '',
    'metadata' => [],
    // Default class for local task implementations.
    'class' => 'Drupal\Core\Menu\MenuLinkDefault',
    'form_class' => 'Drupal\Core\Menu\Form\MenuLinkDefaultForm',
    // The plugin ID. Set by the plugin system based on the top-level YAML key.
    'id' => '',
  ];
  use MenuLinkFieldDefinitions;

  /**
   * The object that discovers plugins managed by this manager.
+4 −31
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@
 */
class MenuTreeStorage implements MenuTreeStorageInterface {

  use MenuLinkFieldDefinitions;

  /**
   * The maximum depth of a menu links tree.
   */
@@ -73,35 +75,6 @@ class MenuTreeStorage implements MenuTreeStorageInterface {
   */
  protected $serializedFields;

  /**
   * List of plugin definition fields.
   *
   * @todo Decide how to keep these field definitions in sync.
   *   https://www.drupal.org/node/2302085
   *
   * @see \Drupal\Core\Menu\MenuLinkManager::$defaults
   *
   * @var array
   */
  protected $definitionFields = [
    'menu_name',
    'route_name',
    'route_parameters',
    'url',
    'title',
    'description',
    'parent',
    'weight',
    'options',
    'expanded',
    'enabled',
    'provider',
    'metadata',
    'class',
    'form_class',
    'id',
  ];

  /**
   * Constructs a new \Drupal\Core\Menu\MenuTreeStorage.
   *
@@ -1198,11 +1171,11 @@ protected function serializedFields() {
  /**
   * Determines fields that are part of the plugin definition.
   *
   * @return array
   * @return string[]
   *   The list of the subset of fields that are part of the plugin definition.
   */
  protected function definitionFields() {
    return $this->definitionFields;
    return array_keys($this->defaults);
  }

  /**