Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663
This commit is contained in:
parent
eb34d130a8
commit
f32e58e4b1
8476 changed files with 211648 additions and 170042 deletions
|
@ -8,10 +8,12 @@ use Drupal\Core\Config\ConfigImporter;
|
|||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Entity\DynamicallyFieldableEntityStorageInterface;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\field\FieldConfigInterface;
|
||||
use Drupal\field\FieldStorageConfigInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
|
||||
/*
|
||||
* Load all public Field API functions. Drupal currently has no
|
||||
|
@ -66,7 +68,7 @@ function field_help($route_name, RouteMatchInterface $route_match) {
|
|||
$field_ui_url = \Drupal::moduleHandler()->moduleExists('field_ui') ? \Drupal::url('help.page', array('name' => 'field_ui')) : '#';
|
||||
$output = '';
|
||||
$output .= '<h3>' . t('About') . '</h3>';
|
||||
$output .= '<p>' . t('The Field module allows custom data fields to be defined for <em>entity</em> types (see below). The Field module takes care of storing, loading, editing, and rendering field data. Most users will not interact with the Field module directly, but will instead use the <a href="!field-ui-help">Field UI module</a> user interface. Module developers can use the Field API to make new entity types "fieldable" and thus allow fields to be attached to them. For more information, see the <a href="!field">online documentation for the Field module</a>.', array('!field-ui-help' => (\Drupal::moduleHandler()->moduleExists('field_ui')) ? \Drupal::url('help.page', array('name' => 'field_ui')) :'#', '!field' => 'https://www.drupal.org/documentation/modules/field')). '</p>';
|
||||
$output .= '<p>' . t('The Field module allows custom data fields to be defined for <em>entity</em> types (see below). The Field module takes care of storing, loading, editing, and rendering field data. Most users will not interact with the Field module directly, but will instead use the <a href=":field-ui-help">Field UI module</a> user interface. Module developers can use the Field API to make new entity types "fieldable" and thus allow fields to be attached to them. For more information, see the <a href=":field">online documentation for the Field module</a>.', array(':field-ui-help' => (\Drupal::moduleHandler()->moduleExists('field_ui')) ? \Drupal::url('help.page', array('name' => 'field_ui')) :'#', ':field' => 'https://www.drupal.org/documentation/modules/field')). '</p>';
|
||||
$output .= '<h3>' . t('Terminology') . '</h3>';
|
||||
$output .= '<dl>';
|
||||
$output .= '<dt>' . t('Entities and entity types') . '</dt>';
|
||||
|
@ -83,7 +85,7 @@ function field_help($route_name, RouteMatchInterface $route_match) {
|
|||
$output .= '<h3>' . t('Uses') . '</h3>';
|
||||
$output .= '<dl>';
|
||||
$output .= '<dt>' . t('Enabling field types, widgets, and formatters') . '</dt>';
|
||||
$output .= '<dd>' . t('The Field module provides the infrastructure for fields; the field types, formatters, and widgets are provided by Drupal core or additional modules. Some of the modules are required; the optional modules can be enabled from the <a href="!modules">Extend administration page</a>. Additional fields, formatters, and widgets may be provided by contributed modules, which you can find in the <a href="!contrib">contributed module section of Drupal.org</a>.', array('!modules' => \Drupal::url('system.modules_list'), '!contrib' => 'https://www.drupal.org/project/modules')) . '</dd>';
|
||||
$output .= '<dd>' . t('The Field module provides the infrastructure for fields; the field types, formatters, and widgets are provided by Drupal core or additional modules. Some of the modules are required; the optional modules can be enabled from the <a href=":modules">Extend administration page</a>. Additional fields, formatters, and widgets may be provided by contributed modules, which you can find in the <a href=":contrib">contributed module section of Drupal.org</a>.', array(':modules' => \Drupal::url('system.modules_list'), ':contrib' => 'https://www.drupal.org/project/modules')) . '</dd>';
|
||||
|
||||
$output .= '<h3>' . t('Field, widget, and formatter information') . '</h3>';
|
||||
|
||||
|
@ -128,6 +130,25 @@ function field_help($route_name, RouteMatchInterface $route_match) {
|
|||
$output .= '<dt>' . t('Provided by Drupal core') . '</dt>';
|
||||
$output .= '<dd>' . t('As mentioned previously, some field types, widgets, and formatters are provided by Drupal core. Here are some notes on how to use some of these:');
|
||||
$output .= '<ul>';
|
||||
$output .= '<li><p>' . t('<strong>Entity Reference</strong> fields allow you to create fields that contain links to other entities (such as content items, taxonomy terms, etc.) within the site. This allows you, for example, to include a link to a user within a content item. For more information, see <a href=":er_do">the online documentation for the Entity Reference module</a>.', array(':er_do' => 'https://drupal.org/documentation/modules/entityreference')) . '</p>';
|
||||
$output .= '<dl>';
|
||||
$output .= '<dt>' . t('Managing and displaying entity reference fields') . '</dt>';
|
||||
$output .= '<dd>' . t('The <em>settings</em> and the <em>display</em> of the entity reference field can be configured separately. See the <a href=":field_ui">Field UI help</a> for more information on how to manage fields and their display.', array(':field_ui' => \Drupal::url('help.page', array('name' => 'field_ui')))) . '</dd>';
|
||||
$output .= '<dt>' . t('Selecting reference type') . '</dt>';
|
||||
$output .= '<dd>' . t('In the field settings you can select which entity type you want to create a reference to.') . '</dd>';
|
||||
$output .= '<dt>' . t('Filtering and sorting reference fields') . '</dt>';
|
||||
$output .= '<dd>' . t('Depending on the chosen entity type, additional filtering and sorting options are available for the list of entities that can be referred to, in the field settings. For example, the list of users can be filtered by role and sorted by name or ID.') . '</dd>';
|
||||
$output .= '<dt>' . t('Displaying a reference') . '</dt>';
|
||||
$output .= '<dd>' . t('An entity reference can be displayed as a simple label with or without a link to the entity. Alternatively, the referenced entity can be displayed as a teaser (or any other available view mode) inside the referencing entity.') . '</dd>';
|
||||
$output .= '<dt>' . t('Configuring form displays') . '</dt>';
|
||||
$output .= '<dd>' . t('Reference fields have several widgets available on the <em>Manage form display</em> page:');
|
||||
$output .= '<ul>';
|
||||
$output .= '<li>' . t('The <em>Check boxes/radio buttons</em> widget displays the existing entities for the entity type as check boxes or radio buttons based on the <em>Allowed number of values</em> set for the field.') . '</li>';
|
||||
$output .= '<li>' . t('The <em>Select list</em> widget displays the existing entities in a drop-down list or scrolling list box based on the <em>Allowed number of values</em> setting for the field.') . '</li>';
|
||||
$output .= '<li>' . t('The <em>Autocomplete</em> widget displays text fields in which users can type entity labels based on the <em>Allowed number of values</em>. The widget can be configured to display all entities that contain the typed characters or restricted to those starting with those characters.') . '</li>';
|
||||
$output .= '<li>' . t('The <em>Autocomplete (Tags style)</em> widget displays a multi-text field in which users can type in a comma-separated list of entity labels.') . '</li>';
|
||||
$output .= '</ul></dd>';
|
||||
$output .= '</dl></li>';
|
||||
$output .= '<li>' . t('<strong>Number fields</strong>: When you add a number field you can choose from three types: <em>decimal</em>, <em>float</em>, and <em>integer</em>. The <em>decimal</em> number field type allows users to enter exact decimal values, with fixed numbers of decimal places. The <em>float</em> number field type allows users to enter approximate decimal values. The <em>integer</em> number field type allows users to enter whole numbers, such as years (for example, 2012) or values (for example, 1, 2, 5, 305). It does not allow decimals.') . '</li>';
|
||||
$output .= '</ul></dd>';
|
||||
$output .= '</dl>';
|
||||
|
@ -186,46 +207,63 @@ function field_entity_bundle_field_info(EntityTypeInterface $entity_type, $bundl
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_bundle_rename().
|
||||
*/
|
||||
function field_entity_bundle_rename($entity_type, $bundle_old, $bundle_new) {
|
||||
$fields = entity_load_multiple_by_properties('field_config', array('entity_type' => $entity_type, 'bundle' => $bundle_old, 'include_deleted' => TRUE));
|
||||
foreach ($fields as $field) {
|
||||
$id_new = $field->getTargetEntityTypeId() . '.' . $bundle_new . '.' . $field->getName();
|
||||
$field->set('id', $id_new);
|
||||
$field->set('bundle', $bundle_new);
|
||||
// Save non-deleted fields.
|
||||
if (!$field->isDeleted()) {
|
||||
$field->allowBundleRename();
|
||||
$field->save();
|
||||
}
|
||||
// Update deleted fields directly in the state storage.
|
||||
else {
|
||||
$state = \Drupal::state();
|
||||
$deleted_fields = $state->get('field.field.deleted') ?: array();
|
||||
$deleted_fields[$field->uuid] = $field->toArray();
|
||||
$state->set('field.field.deleted', $deleted_fields);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_bundle_delete().
|
||||
*
|
||||
* This deletes the data for the field as well as the field themselves. This
|
||||
* function actually just marks the data and fields as deleted, leaving the
|
||||
* garbage collection for a separate process, because it is not always
|
||||
* possible to delete this much data in a single page request (particularly
|
||||
* since for some field types, the deletion is more than just a simple DELETE
|
||||
* query).
|
||||
*/
|
||||
function field_entity_bundle_delete($entity_type, $bundle) {
|
||||
function field_entity_bundle_delete($entity_type_id, $bundle) {
|
||||
$storage = \Drupal::entityManager()->getStorage('field_config');
|
||||
// Get the fields on the bundle.
|
||||
$fields = entity_load_multiple_by_properties('field_config', array('entity_type' => $entity_type, 'bundle' => $bundle));
|
||||
$fields = $storage->loadByProperties(['entity_type' => $entity_type_id, 'bundle' => $bundle]);
|
||||
// This deletes the data for the field as well as the field themselves. This
|
||||
// function actually just marks the data and fields as deleted, leaving the
|
||||
// garbage collection for a separate process, because it is not always
|
||||
// possible to delete this much data in a single page request (particularly
|
||||
// since for some field types, the deletion is more than just a simple DELETE
|
||||
// query).
|
||||
foreach ($fields as $field) {
|
||||
$field->delete();
|
||||
}
|
||||
|
||||
// We are duplicating the work done by
|
||||
// \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::onDependencyRemoval()
|
||||
// because we need to take into account bundles that are not provided by a
|
||||
// config entity type so they are not part of the config dependencies.
|
||||
|
||||
// Gather a list of all entity reference fields.
|
||||
$map = \Drupal::entityManager()->getFieldMapByFieldType('entity_reference');
|
||||
$ids = [];
|
||||
foreach ($map as $type => $info) {
|
||||
foreach ($info as $name => $data) {
|
||||
foreach ($data['bundles'] as $bundle_name) {
|
||||
$ids[] = "$type.$bundle_name.$name";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update the 'target_bundles' handler setting if needed.
|
||||
foreach (FieldConfig::loadMultiple($ids) as $field_config) {
|
||||
if ($field_config->getSetting('target_type') == $entity_type_id) {
|
||||
$handler_settings = $field_config->getSetting('handler_settings');
|
||||
if (isset($handler_settings['target_bundles'][$bundle])) {
|
||||
unset($handler_settings['target_bundles'][$bundle]);
|
||||
$field_config->setSetting('handler_settings', $handler_settings);
|
||||
$field_config->save();
|
||||
|
||||
// In case we deleted the only target bundle allowed by the field we
|
||||
// have to log a warning message because the field will not function
|
||||
// correctly anymore.
|
||||
if ($handler_settings['target_bundles'] === []) {
|
||||
\Drupal::logger('entity_reference')->critical('The %target_bundle bundle (entity type: %target_entity_type) was deleted. As a result, the %field_name entity reference field (entity_type: %entity_type, bundle: %bundle) no longer has any valid bundle it can reference. The field is not working correctly anymore and has to be adjusted.', [
|
||||
'%target_bundle' => $bundle,
|
||||
'%target_entity_type' => $entity_type_id,
|
||||
'%field_name' => $field_config->getName(),
|
||||
'%entity_type' => $field_config->getTargetEntityTypeId(),
|
||||
'%bundle' => $field_config->getTargetBundle()
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -304,3 +342,65 @@ function field_form_config_admin_import_form_alter(&$form, FormStateInterface $f
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_ENTITY_TYPE_update() for 'field_storage_config'.
|
||||
*
|
||||
* Reset the field handler settings, when the storage target_type is changed on
|
||||
* an entity reference field.
|
||||
*/
|
||||
function field_field_storage_config_update(FieldStorageConfigInterface $field_storage) {
|
||||
if ($field_storage->isSyncing()) {
|
||||
// Don't change anything during a configuration sync.
|
||||
return;
|
||||
}
|
||||
|
||||
// Act on all sub-types of the entity_reference field type.
|
||||
/** @var \Drupal\Core\Field\FieldTypePluginManager $field_type_manager */
|
||||
$field_type_manager = \Drupal::service('plugin.manager.field.field_type');
|
||||
$item_class = 'Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem';
|
||||
$class = $field_type_manager->getPluginClass($field_storage->getType());
|
||||
if ($class !== $item_class && !is_subclass_of($class, $item_class)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If target_type changed, reset the handler in the fields using that storage.
|
||||
if ($field_storage->getSetting('target_type') !== $field_storage->original->getSetting('target_type')) {
|
||||
foreach ($field_storage->getBundles() as $bundle) {
|
||||
$field = FieldConfig::loadByName($field_storage->getTargetEntityTypeId(), $bundle, $field_storage->getName());
|
||||
// Reset the handler settings. This triggers field_field_config_presave(),
|
||||
// which will take care of reassigning the handler to the correct
|
||||
// derivative for the new target_type.
|
||||
$field->setSetting('handler_settings', []);
|
||||
$field->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_ENTITY_TYPE_presave() for 'field_config'.
|
||||
*
|
||||
* Determine the selection handler plugin ID for an entity reference field.
|
||||
*/
|
||||
function field_field_config_presave(FieldConfigInterface $field) {
|
||||
// Don't change anything during a configuration sync.
|
||||
if ($field->isSyncing()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Act on all sub-types of the entity_reference field type.
|
||||
/** @var \Drupal\Core\Field\FieldTypePluginManager $field_type_manager */
|
||||
$field_type_manager = \Drupal::service('plugin.manager.field.field_type');
|
||||
$item_class = 'Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem';
|
||||
$class = $field_type_manager->getPluginClass($field->getType());
|
||||
if ($class !== $item_class && !is_subclass_of($class, $item_class)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure the selection handler plugin is the correct derivative for the
|
||||
// target entity type.
|
||||
$target_type = $field->getFieldStorageDefinition()->getSetting('target_type');
|
||||
$selection_manager = \Drupal::service('plugin.manager.entity_reference_selection');
|
||||
list($current_handler) = explode(':', $field->getSetting('handler'), 2);
|
||||
$field->setSetting('handler', $selection_manager->getPluginId($target_type, $current_handler));
|
||||
}
|
||||
|
|
Reference in a new issue