You are here

menu_link.module in Menu Link (Field) 2.0.x

Same filename and directory in other branches
  1. 8 menu_link.module
  2. 7 menu_link.module

Provides a menu link field.

File

menu_link.module
View source
<?php

/**
 * @file
 * Provides a menu link field.
 */
use Drupal\Core\Form\FormStateInterface;

/**
 * Implements hook_form_FORM_ID_alter().
 */
function menu_link_form_field_ui_field_storage_edit_form_alter(&$form, FormStateInterface $form_state) {
  if ($form['#field']
    ->getType() === 'menu_link') {

    // We only support posting one menu link at a time.
    // @todo - this is a hack and should be managed by the field definition.
    // https://www.drupal.org/node/2403703
    $form['field_storage']['cardinality_container']['cardinality']['#default_value'] = 1;
    $form['field_storage']['cardinality_container']['#access'] = FALSE;
  }
}

/**
 * Implements hook_menu_implements_alter().
 */
function menu_link_module_implements_alter(&$implementations, $hook) {

  // Disable the menu_ui functionality.
  if ($hook === 'form_node_form_alter') {
    unset($implementations['menu_ui']);
  }
}

Functions