entity_extra_field_ui.module in Entity Extra Field 2.0.x
Same filename and directory in other branches
File
modules/entity_extra_field_ui/entity_extra_field_ui.moduleView source
<?php
/**
* @file
* The hook implementation for the entity extra field UI module.
*/
declare (strict_types=1);
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Url;
/**
* Implements hook_entity_operation().
*/
function entity_extra_field_ui_entity_operation(EntityInterface $entity) : array {
$operations = [];
if (entity_extra_field_ui_entity_has_field_ui($entity)) {
$account = \Drupal::currentUser();
$entity_type = $entity
->getEntityType();
$base_entity_type_id = $entity_type
->getBundleOf();
if ($account
->hasPermission('administer entity extra field')) {
$operations['manage-extra-fields'] = [
'title' => t('Manage extra fields'),
'weight' => 17,
'url' => Url::fromRoute("entity.{$base_entity_type_id}.extra_fields", [
$entity
->getEntityTypeId() => $entity
->id(),
]),
];
}
}
return $operations;
}
/**
* Entity has field UI.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* An entity to check if a field UI exist.
*
* @return bool
* Return TRUE if the entity has field UI; otherwise FALSE.
*
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
function entity_extra_field_ui_entity_has_field_ui(EntityInterface $entity) : bool {
$entity_type = $entity
->getEntityType();
if (!$entity_type instanceof EntityTypeInterface || $entity_type
->getBundleOf() === NULL) {
return FALSE;
}
$definition = \Drupal::entityTypeManager()
->getDefinition($entity_type
->getBundleOf());
if ($definition
->get('field_ui_base_route') === NULL) {
return FALSE;
}
return TRUE;
}
Functions
Name | Description |
---|---|
entity_extra_field_ui_entity_has_field_ui | Entity has field UI. |
entity_extra_field_ui_entity_operation | Implements hook_entity_operation(). |