' . t('About') . '';
$output .= '
' . t('The Field module allows custom data fields to be defined for entity types (entities include content items, comments, user accounts, and taxonomy terms). 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 Field UI module 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 online handbook entry for Field module.', array('@field-ui-help' => url('admin/help/field_ui'), '@field' => 'http://drupal.org/documentation/modules/field')) . '
';
$output .= '' . t('Uses') . '
';
$output .= '';
$output .= '- ' . t('Enabling field types') . '
';
$output .= '- ' . t('The Field module provides the infrastructure for fields and field attachment; the field types and input widgets themselves are provided by additional modules. The modules can be enabled from the Modules administration page. Drupal core includes the following field type modules: Text, Number, Email, Link, Telephone, Image, File, Options, Taxonomy, and Entity Reference. Additional fields and widgets may be provided by contributed modules, which you can find in the contributed module section of Drupal.org.', array('@modules' => url('admin/modules'), '@contrib' => 'http://drupal.org/project/modules', '@options' => url('admin/help/options')));
// Make a list of all widget and field modules currently enabled, ordered
// by displayed module name (module names are not translated).
$items = array();
$info = system_get_info('module');
$field_widgets = \Drupal::service('plugin.manager.field.widget')->getDefinitions();
$field_types = \Drupal::service('plugin.manager.field.field_type')->getUiDefinitions();
$providers = array();
foreach (array_merge($field_types, $field_widgets) as $plugin) {
$providers[] = $plugin['provider'];
}
$providers = array_unique($providers);
sort($providers);
foreach ($providers as $provider) {
// Skip plugins provided by core components as they do not implement
// hook_help().
if (isset($info[$provider]['name'])) {
$display = $info[$provider]['name'];
if (\Drupal::moduleHandler()->implementsHook($provider, 'help')) {
$items[] = l($display, 'admin/help/' . $provider);
}
else {
$items[] = $display;
}
}
}
if ($items) {
$output .= ' ' . t('Currently enabled field and input widget modules:');
$item_list = array(
'#theme' => 'item_list',
'#items' => $items,
);
$output .= drupal_render($item_list);
}
return $output;
}
}
/**
* Implements hook_cron().
*/
function field_cron() {
// Do a pass of purging on deleted Field API data, if any exists.
$limit = \Drupal::config('field.settings')->get('purge_batch_size');
field_purge_batch($limit);
}
/**
* Implements hook_system_info_alter().
*
* Goes through a list of all modules that provide a field type and makes them
* required if there are any active fields of that type.
*/
function field_system_info_alter(&$info, Extension $file, $type) {
// It is not safe to call entity_load_multiple_by_properties() during
// maintenance mode.
if ($type == 'module' && !defined('MAINTENANCE_MODE')) {
$fields = entity_load_multiple_by_properties('field_config', array('module' => $file->getName(), 'include_deleted' => TRUE));
if ($fields) {
$info['required'] = TRUE;
// Provide an explanation message (only mention pending deletions if there
// remains no actual, non-deleted fields)
$non_deleted = FALSE;
foreach ($fields as $field) {
if (empty($field->deleted)) {
$non_deleted = TRUE;
break;
}
}
if ($non_deleted) {
if (\Drupal::moduleHandler()->moduleExists('field_ui')) {
$explanation = t('Field type(s) in use - see Field list', array('@fields-page' => url('admin/reports/fields')));
}
else {
$explanation = t('Fields type(s) in use');
}
}
else {
$explanation = t('Fields pending deletion');
}
$info['explanation'] = $explanation;
}
}
}
/**
* Implements hook_entity_bundle_field_info().
*/
function field_entity_bundle_field_info(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) {
if ($entity_type->isFieldable()) {
// Configurable fields, which are always attached to a specific bundle, are
// added 'by bundle'.
return Field::fieldInfo()->getBundleInstances($entity_type->id(), $bundle);
}
}
/**
* Implements hook_entity_bundle_create().
*/
function field_entity_bundle_create($entity_type, $bundle) {
// Clear the cache.
field_cache_clear();
}
/**
* Implements hook_entity_bundle_rename().
*/
function field_entity_bundle_rename($entity_type, $bundle_old, $bundle_new) {
$instances = entity_load_multiple_by_properties('field_instance_config', array('entity_type' => $entity_type, 'bundle' => $bundle_old));
foreach ($instances as $instance) {
if ($instance->entity_type == $entity_type && $instance->bundle == $bundle_old) {
$id_new = $instance->entity_type . '.' . $bundle_new . '.' . $instance->field_name;
$instance->id = $id_new;
$instance->bundle = $bundle_new;
$instance->allowBundleRename();
$instance->save();
}
}
// Clear the field cache.
field_cache_clear();
}
/**
* Implements hook_entity_bundle_delete().
*
* This deletes the data for the field instances as well as the field instances
* themselves. This function actually just marks the data and field instances 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) {
// Get the instances on the bundle. entity_load_multiple_by_properties() must
// be used here since field_info_instances() does not return instances for
// disabled entity types or bundles.
$instances = entity_load_multiple_by_properties('field_instance_config', array('entity_type' => $entity_type, 'bundle' => $bundle));
foreach ($instances as $instance) {
$instance->delete();
}
// Clear the cache.
field_cache_clear();
}
/**
* Implements hook_rebuild().
*/
function field_rebuild() {
field_cache_clear();
}
/**
* Implements hook_modules_installed().
*/
function field_modules_installed($modules) {
field_cache_clear();
}
/**
* Implements hook_modules_uninstalled().
*/
function field_modules_uninstalled($modules) {
field_cache_clear();
}
/**
* Clears the field info and field data caches.
*/
function field_cache_clear() {
\Drupal::cache('entity')->deleteAll();
field_info_cache_clear();
}
/**
* Filters an HTML string to prevent cross-site-scripting (XSS) vulnerabilities.
*
* Like filter_xss_admin(), but with a shorter list of allowed tags.
*
* Used for items entered by administrators, like field descriptions, allowed
* values, where some (mainly inline) mark-up may be desired (so
* drupal_htmlspecialchars() is not acceptable).
*
* @param $string
* The string with raw HTML in it.
*
* @return
* An XSS safe version of $string, or an empty string if $string is not valid
* UTF-8.
*/
function field_filter_xss($string) {
return Html::normalize(Xss::filter($string, _field_filter_xss_allowed_tags()));
}
/**
* Returns a list of tags allowed by field_filter_xss().
*/
function _field_filter_xss_allowed_tags() {
return array('a', 'b', 'big', 'code', 'del', 'em', 'i', 'ins', 'pre', 'q', 'small', 'span', 'strong', 'sub', 'sup', 'tt', 'ol', 'ul', 'li', 'p', 'br', 'img');
}
/**
* Returns a human-readable list of allowed tags for display in help texts.
*/
function _field_filter_xss_display_allowed_tags() {
return '<' . implode('> <', _field_filter_xss_allowed_tags()) . '>';
}
/**
* @} End of "defgroup field".
*/
/**
* Assembles a partial entity structure with initial IDs.
*
* @param object $ids
* An object with the properties entity_type (required), entity_id (required),
* revision_id (optional) and bundle (optional).
*
* @return \Drupal\Core\Entity\EntityInterface
* An entity, initialized with the provided IDs.
*/
function _field_create_entity_from_ids($ids) {
$id_properties = array();
$entity_type = \Drupal::entityManager()->getDefinition($ids->entity_type);
if ($id_key = $entity_type->getKey('id')) {
$id_properties[$id_key] = $ids->entity_id;
}
if (isset($ids->revision_id) && $revision_key = $entity_type->getKey('revision')) {
$id_properties[$revision_key] = $ids->revision_id;
}
if (isset($ids->bundle) && $bundle_key = $entity_type->getKey('bundle')) {
$id_properties[$bundle_key] = $ids->bundle;
}
return entity_create($ids->entity_type, $id_properties);
}
/**
* Implements hook_hook_info().
*/
function field_hook_info() {
$hooks['field_views_data'] = array(
'group' => 'views',
);
$hooks['field_views_data_alter'] = array(
'group' => 'views',
);
return $hooks;
}