115 lines
6.9 KiB
Plaintext
115 lines
6.9 KiB
Plaintext
<?php
|
|
|
|
/**
|
|
* @file
|
|
* Manage the entity system.
|
|
*
|
|
* The module is mostly an anchor point for configuration items owned by the
|
|
* entity system.
|
|
*/
|
|
|
|
use Drupal\Core\Config\Entity\ConfigEntityStorage;
|
|
|
|
/**
|
|
* Implements hook_help().
|
|
*/
|
|
function entity_help($path, $arg) {
|
|
switch ($path) {
|
|
case 'admin/help#entity':
|
|
$output = '';
|
|
$output .= '<h3>' . t('About') . '</h3>';
|
|
$output .= '<p>' . t('The Entity module manages various types of content and configuration for the website. This information is collectively know as "entities", which are grouped into "entity types" (such as the main site content, comments, custom blocks, taxonomy terms, user accounts, and views configuration). Some entity types are further grouped into sub-types (for example, you could have article and page content types within the main site content entity type, and tag and category vocabularies within the taxonomy term entity type); other entity types, such as user accounts, do not have sub-types.') . '</p>';
|
|
$output .= '<p>' . t('Content entity types store most of their text, file, and other information in fields. See the <a href="!field">Field module help</a> and the <a href="!field_ui">Field UI help</a> pages for general information on fields and how to create and manage them.', array('!field' => \Drupal::url('help.page', array('name' => 'field')), '!field_ui' => \Drupal::url('help.page', array('name' => 'field_ui')))) . '</p>';
|
|
$output .= '<p>' . t('Configuration entity types are used to store configuration information for your site, such as individual views in the Views module, and settings for your main site content types. Configuration stored in this way can be exported, imported, and managed using the Configuration Manager module. See the <a href="!config-help">Configuration Manager module help</a> page for more information.', array('!config-help' => \Drupal::url('help.page', array('name' => 'config')))) . '</p>';
|
|
$output .= '<p>' . t('For more information, see the <a href="!entity_documentation">online documentation for the Entity module</a>.', array('!entity_documentation' => 'https://drupal.org/documentation/modules/entity')) . '</p>';
|
|
$output .= '<h3>' . t('Uses') . '</h3>';
|
|
$output .= '<dl>';
|
|
$output .= '<dt>' . t('Managing view modes') . '</dt>';
|
|
$output .= '<dd>' . t('Each content entity can have various "modes" for viewing. For instance, a content item could be viewed in full content mode on its own page, teaser mode in a list, or RSS mode in a feed. You can create, edit the names of, and delete view modes on the <a href="!view-modes">View modes page</a>. Once a view mode has been set up, you can choose and format fields for the view mode within each entity sub-type on the Manage display page. See the <a href="!field_ui">Field UI module help page</a> for more information.', array('!view-modes' => \Drupal::url('entity.view_mode_list'), '!field_ui' => \Drupal::url('help.page', array('name' => 'field_ui')))) . '</dd>';
|
|
$output .= '<dt>' . t('Managing form modes') . '</dt>';
|
|
$output .= '<dd>' . t('Each content entity can have various editing forms appropriate for different situations, which are known as "form modes". For instance, you might want to define a quick editing mode that allows users to edit the most important fields, and a full editing mode that gives access to all the fields. You can create, edit the names of, and delete form modes on the <a href="!form-modes">Manage custom form modes page</a>. Once a form mode has been set up, you can choose which fields are available on that form within each entity sub-type on the Manage form display page. See the <a href="!field_ui">Field UI module help page</a> for more information.', array('!form-modes' => \Drupal::url('entity.form_mode_list'), '!field_ui' => \Drupal::url('help.page', array('name' => 'field_ui')))) . '</dd>';
|
|
$output .= '</dl>';
|
|
return $output;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Implements hook_permission().
|
|
*/
|
|
function entity_permission() {
|
|
return array(
|
|
'administer display modes' => array(
|
|
'title' => t('Add, edit, and delete custom display modes.'),
|
|
),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Implements hook_entity_bundle_rename().
|
|
*/
|
|
function entity_entity_bundle_rename($entity_type_id, $bundle_old, $bundle_new) {
|
|
// Rename entity displays.
|
|
$entity_type = \Drupal::entityManager()->getDefinition('entity_view_display');
|
|
if ($bundle_old !== $bundle_new) {
|
|
$ids = \Drupal::configFactory()->listAll('entity.view_display.' . $entity_type_id . '.' . $bundle_old . '.');
|
|
foreach ($ids as $id) {
|
|
$id = ConfigEntityStorage::getIDFromConfigName($id, $entity_type->getConfigPrefix());
|
|
$display = entity_load('entity_view_display', $id);
|
|
$new_id = $entity_type_id . '.' . $bundle_new . '.' . $display->mode;
|
|
$display->set('id', $new_id);
|
|
$display->bundle = $bundle_new;
|
|
$display->save();
|
|
}
|
|
}
|
|
|
|
// Rename entity form displays.
|
|
$entity_type = \Drupal::entityManager()->getDefinition('entity_form_display');
|
|
if ($bundle_old !== $bundle_new) {
|
|
$ids = \Drupal::configFactory()->listAll('entity.form_display.' . $entity_type_id . '.' . $bundle_old . '.');
|
|
foreach ($ids as $id) {
|
|
$id = ConfigEntityStorage::getIDFromConfigName($id, $entity_type->getConfigPrefix());
|
|
$form_display = entity_load('entity_form_display', $id);
|
|
$new_id = $entity_type_id . '.' . $bundle_new . '.' . $form_display->mode;
|
|
$form_display->set('id', $new_id);
|
|
$form_display->bundle = $bundle_new;
|
|
$form_display->save();
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Implements hook_entity_bundle_delete().
|
|
*/
|
|
function entity_entity_bundle_delete($entity_type_id, $bundle) {
|
|
// Remove entity displays of the deleted bundle.
|
|
$entity_type = \Drupal::entityManager()->getDefinition('entity_view_display');
|
|
$ids = \Drupal::configFactory()->listAll('entity.view_display.' . $entity_type_id . '.' . $bundle . '.');
|
|
foreach ($ids as &$id) {
|
|
$id = ConfigEntityStorage::getIDFromConfigName($id, $entity_type->getConfigPrefix());
|
|
}
|
|
entity_delete_multiple('entity_view_display', $ids);
|
|
|
|
// Remove entity form displays of the deleted bundle.
|
|
$entity_type = \Drupal::entityManager()->getDefinition('entity_form_display');
|
|
$ids = \Drupal::configFactory()->listAll('entity.form_display.' . $entity_type_id . '.' . $bundle . '.');
|
|
foreach ($ids as &$id) {
|
|
$id = ConfigEntityStorage::getIDFromConfigName($id, $entity_type->getConfigPrefix());
|
|
}
|
|
entity_delete_multiple('entity_form_display', $ids);
|
|
}
|
|
|
|
/**
|
|
* Implements hook_module_preuninstall().
|
|
*/
|
|
function entity_module_preuninstall($module) {
|
|
// Clean up all entity bundles (including field instances) of every entity
|
|
// type provided by the module that is being uninstalled.
|
|
foreach (\Drupal::entityManager()->getDefinitions() as $entity_type_id => $entity_type) {
|
|
if ($entity_type->getProvider() == $module) {
|
|
foreach (array_keys(entity_get_bundles($entity_type_id)) as $bundle) {
|
|
entity_invoke_bundle_hook('delete', $entity_type_id, $bundle);
|
|
}
|
|
}
|
|
}
|
|
}
|