You are here

function menu_item_role_access_entity_base_field_info in Menu Item Role Access 8

Same name and namespace in other branches
  1. 8.2 menu_item_role_access.module \menu_item_role_access_entity_base_field_info()

Implements hook_entity_base_field_info().

File

./menu_item_role_access.module, line 19
Menu Item Role Access module.

Code

function menu_item_role_access_entity_base_field_info(EntityTypeInterface $entity_type) {
  $fields = [];
  if ($entity_type
    ->id() == 'menu_link_content') {

    // Get config.
    $config = \Drupal::config('menu_item_role_access.config');
    $fields['menu_item_roles'] = BaseFieldDefinition::create('entity_reference')
      ->setLabel(t('Menu Item Roles'))
      ->setDescription(t('Set the roles allowed for this menu item.'))
      ->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED)
      ->setSetting('target_type', 'user_role')
      ->setDisplayOptions('view', [
      'label' => 'hidden',
      'type' => 'author',
      'weight' => 0,
    ])
      ->setDisplayOptions('form', [
      'type' => 'options_buttons',
      'weight' => 3,
      'settings' => [
        'display_label' => TRUE,
      ],
    ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE);
    $fields['menu_item_override_children'] = BaseFieldDefinition::create('boolean')
      ->setLabel(t('Override children'))
      ->setDescription(t('With this option checked the children will adhere to the above selected roles. Children may then again override their own children by setting this option. Please note that you may need to turn the option "Overwrite internal link target access check" on for this to work properly.'))
      ->setCardinality(1)
      ->setDisplayOptions('view', [
      'label' => 'hidden',
    ])
      ->setDisplayOptions('form', [
      'type' => 'checkbox',
      'weight' => 4,
      'settings' => [
        'display_label' => TRUE,
      ],
    ])
      ->setDisplayConfigurable('view', TRUE)
      ->setDisplayConfigurable('form', TRUE);
  }
  return $fields;
}