You are here

function menu_attributes_get_menu_attribute_info in Menu Attributes 8

Same name and namespace in other branches
  1. 6.2 menu_attributes.module \menu_attributes_get_menu_attribute_info()
  2. 6 menu_attributes.module \menu_attributes_get_menu_attribute_info()
  3. 7 menu_attributes.module \menu_attributes_get_menu_attribute_info()

Fetch an array of menu attributes.

2 calls to menu_attributes_get_menu_attribute_info()
MenuAttributesSettingsForm::buildForm in src/Form/MenuAttributesSettingsForm.php
Form constructor.
_menu_attributes_form_alter in ./menu_attributes.module
Add the menu attributes to a menu item edit form.

File

./menu_attributes.module, line 111
Alters the menu item form to allow the administrator to specify additional attributes for the menu link

Code

function menu_attributes_get_menu_attribute_info() {
  $module_handler = \Drupal::moduleHandler();
  $attributes = $module_handler
    ->invokeAll('menu_attribute_info');
  $config = \Drupal::config('menu_attributes.settings');

  // Merge in default values.
  foreach ($attributes as $attribute => &$info) {
    $info += [
      'form' => [],
      'enabled' => $config
        ->get('attribute_enable.' . $attribute),
    ];
    $info['form'] += [
      '#type' => 'textfield',
      '#title' => $info['label'],
      '#description' => isset($info['description']) ? $info['description'] : '',
      '#default_value' => $config
        ->get('attribute_default.' . $attribute),
    ];
  }
  $module_handler
    ->alter('menu_attribute_info', $attributes);
  return $attributes;
}