You are here

class MenuDetails in Menu Link (Field) 2.0.x

Provides a pre-render callback for menu field details.

Hierarchy

Expanded class hierarchy of MenuDetails

1 file declares its use of MenuDetails
MenuLinkWidget.php in src/Plugin/Field/FieldWidget/MenuLinkWidget.php

File

src/Render/Element/MenuDetails.php, line 10

Namespace

Drupal\menu_link\Render\Element
View source
class MenuDetails implements TrustedCallbackInterface {

  /**
   * {@inheritdoc}
   */
  public static function trustedCallbacks() {
    return [
      'preRender',
    ];
  }

  /**
   * Pre-render callback: Builds a renderable array for the menu link widget.
   *
   * @param array $element
   *   A renderable array.
   *
   * @return array
   *   A renderable array.
   */
  public static function preRender($element) {
    $element['menu']['enabled'] = $element['enabled'];
    $element['menu']['title'] = $element['title'];
    $element['menu']['description'] = $element['description'];
    $element['menu']['menu_parent'] = $element['menu_parent'];
    $element['menu']['weight'] = $element['weight'];

    // Hide the elements when enabled is disabled.
    foreach ([
      'title',
      'description',
      'menu_parent',
      'weight',
    ] as $form_element) {
      $element['menu'][$form_element]['#states'] = [
        'invisible' => [
          'input[name="' . $element['menu']['enabled']['#name'] . '"]' => [
            'checked' => FALSE,
          ],
        ],
      ];
    }
    unset($element['enabled'], $element['title'], $element['description'], $element['menu_parent'], $element['weight']);
    return $element;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MenuDetails::preRender public static function Pre-render callback: Builds a renderable array for the menu link widget.
MenuDetails::trustedCallbacks public static function Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface::trustedCallbacks
TrustedCallbackInterface::THROW_EXCEPTION constant Untrusted callbacks throw exceptions.
TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION constant Untrusted callbacks trigger silenced E_USER_DEPRECATION errors.
TrustedCallbackInterface::TRIGGER_WARNING constant Untrusted callbacks trigger E_USER_WARNING errors.