diff --git a/core/modules/field/field.deprecated.inc b/core/modules/field/field.deprecated.inc index 31c67580fb2..02f60e3ec2e 100644 --- a/core/modules/field/field.deprecated.inc +++ b/core/modules/field/field.deprecated.inc @@ -7,156 +7,10 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\ContentEntityInterface; -use Drupal\Core\Language\Language; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\field\Field; -/** - * Returns information about field types. - * - * @param $field_type - * (optional) A field type name. If omitted, all field types will be returned. - * - * @return - * Either a field type definition, or an array of all existing field types, - * keyed by field type name. - * - * @deprecated as of Drupal 8.0. Use - * \Drupal::service('plugin.manager.field.field_type')->getDefinition() - * or - * \Drupal::service('plugin.manager.field.field_type')->getConfigurableDefinitions(). - */ -function field_info_field_types($field_type = NULL) { - if ($field_type) { - return \Drupal::service('plugin.manager.field.field_type')->getDefinition($field_type); - } - else { - return \Drupal::service('plugin.manager.field.field_type')->getConfigurableDefinitions(); - } -} - -/** - * Returns a field type's default settings. - * - * @param $type - * A field type name. - * - * @return - * The field type's default settings, or an empty array if type or settings - * are not defined. - * - * @deprecated as of Drupal 8.0. Use - * \Drupal::service('plugin.manager.field.field_type')->getDefaultSettings() - */ -function field_info_field_settings($type) { - return \Drupal::service('plugin.manager.field.field_type')->getDefaultSettings($type); -} - -/** - * Returns a field type's default instance settings. - * - * @param $type - * A field type name. - * - * @return - * The field type's default instance settings, or an empty array if type or - * settings are not defined. - * - * @deprecated as of Drupal 8.0. Use - * \Drupal::service('plugin.manager.field.field_type')->getDefaultInstanceSettings() - */ -function field_info_instance_settings($type) { - return \Drupal::service('plugin.manager.field.field_type')->getDefaultInstanceSettings($type); -} - -/** - * Returns information about field widgets from AnnotatedClassDiscovery. - * - * @param string $widget_type - * (optional) A widget type name. If omitted, all widget types will be - * returned. - * - * @return array - * Either a single widget type description, as provided by class annotations, - * or an array of all existing widget types, keyed by widget type name. - * - * @deprecated as of Drupal 8.0. Use - * \Drupal::service('plugin.manager.field.widget')->getDefinition() - * or - * \Drupal::service('plugin.manager.field.widget')->getDefinitions() - */ -function field_info_widget_types($widget_type = NULL) { - if ($widget_type) { - return \Drupal::service('plugin.manager.field.widget')->getDefinition($widget_type); - } - else { - return \Drupal::service('plugin.manager.field.widget')->getDefinitions(); - } -} - -/** - * Returns a field widget's default settings. - * - * @param $type - * A widget type name. - * - * @return - * The widget type's default settings, as provided by - * hook_field_widget_info(), or an empty array if type or settings are - * undefined. - * - * @deprecated as of Drupal 8.0. Use - * \Drupal::service('plugin.manager.field.widget')->getDefaultSettings() - */ -function field_info_widget_settings($type) { - return \Drupal::service('plugin.manager.field.widget')->getDefaultSettings($type); -} - -/** - * Returns information about field formatters from hook_field_formatter_info(). - * - * @param string $formatter_type - * (optional) A formatter type name. If omitted, all formatter types will be - * returned. - * - * @return array - * Either a single formatter type description, as provided by class - * annotations, or an array of all existing formatter types, keyed by - * formatter type name. - * - * @deprecated as of Drupal 8.0. Use - * \Drupal::service('plugin.manager.field.formatter')->getDefinition() - * or - * \Drupal::service('plugin.manager.field.formatter')->getDefinitions() - */ -function field_info_formatter_types($formatter_type = NULL) { - if ($formatter_type) { - return \Drupal::service('plugin.manager.field.formatter')->getDefinition($formatter_type); - } - else { - return \Drupal::service('plugin.manager.field.formatter')->getDefinitions(); - } -} - -/** - * Returns a field formatter's default settings. - * - * @param $type - * A field formatter type name. - * - * @return - * The formatter type's default settings, as provided by - * hook_field_formatter_info(), or an empty array if type or settings are - * undefined. - * - * @deprecated as of Drupal 8.0. Use - * \Drupal::service('plugin.manager.field.formatter')->getDefaultSettings() - */ -function field_info_formatter_settings($type) { - return \Drupal::service('plugin.manager.field.formatter')->getDefaultSettings($type); -} - /** * Returns a lightweight map of fields across bundles. * @@ -321,120 +175,6 @@ function field_info_instance($entity_type, $field_name, $bundle_name) { return Field::fieldInfo()->getInstance($entity_type, $bundle_name, $field_name); } -/** - * Reads a single field record directly from the database. - * - * Generally, you should use the field_info_field() instead. - * - * This function will not return deleted fields. Use field_read_fields() instead - * for this purpose. - * - * @param $entity_type - * The entity type. - * @param $field_name - * The field name to read. - * @param array $include_additional - * Additional properties to match. - * - * @return - * A field definition array, or FALSE. - * - * @deprecated as of Drupal 8.0. Use - * entity_load('field_entity', 'field_name'). - */ -function field_read_field($entity_type, $field_name, $include_additional = array()) { - $fields = field_read_fields(array('entity_type' => $entity_type, 'name' => $field_name), $include_additional); - return $fields ? current($fields) : FALSE; -} - -/** - * Reads in fields that match an array of conditions. - * - * @param array $conditions - * An array of conditions to match against. Keys are names of properties - * found in field configuration files, and values are conditions to match. - * @param array $include_additional - * The default behavior of this function is to not return fields that have - * been deleted. Setting $include_additional['include_deleted'] to TRUE will - * override this behavior. - * - * @return - * An array of fields matching $params. If - * $include_additional['include_deleted'] is TRUE, the array is keyed by - * field ID, otherwise it is keyed by field name. - * - * @deprecated as of Drupal 8.0. Use - * entity_load_multiple_by_properties('field_entity', $conditions). - */ -function field_read_fields($conditions = array(), $include_additional = array()) { - // Include deleted fields if specified either in the $include_additional or - // the $conditions parameters. - $include_deleted = (isset($include_additional['include_deleted']) && $include_additional['include_deleted']) || (isset($conditions['deleted']) && $conditions['deleted']); - - // Pass include_deleted to the $conditions array. - $conditions['include_deleted'] = $include_deleted; - - return entity_load_multiple_by_properties('field_entity', $conditions); -} - -/** - * Reads a single instance record from the database. - * - * Generally, you should use field_info_instance() instead, as it provides - * caching and allows other modules the opportunity to append additional - * formatters, widgets, and other information. - * - * @param $entity_type - * The type of entity to which the field is bound. - * @param $field_name - * The field name to read. - * @param $bundle - * The bundle to which the field is bound. - * @param array $include_additional - * The default behavior of this function is to not return an instance that has - * been deleted. Setting $include_additional['include_deleted'] to TRUE will - * override this behavior. - * - * @return - * An instance structure, or FALSE. - * - * @deprecated as of Drupal 8.0. Use - * entity_load('field_instance', 'field_name'). - */ -function field_read_instance($entity_type, $field_name, $bundle, $include_additional = array()) { - $instances = field_read_instances(array('entity_type' => $entity_type, 'field_name' => $field_name, 'bundle' => $bundle), $include_additional); - return $instances ? current($instances) : FALSE; -} - -/** - * Reads in field instances that match an array of conditions. - * - * @param $param - * An array of properties to use in selecting a field instance. Keys are names - * of properties found in field instance configuration files, and values are - * conditions to match. - * @param $include_additional - * The default behavior of this function is to not return field instances that - * have been marked deleted. Setting - * $include_additional['include_deleted'] to TRUE will override this behavior. - * - * @return - * An array of instances matching the arguments. - * - * @deprecated as of Drupal 8.0. Use - * entity_load_multiple_by_properties('field_instance', $conditions). - */ -function field_read_instances($conditions = array(), $include_additional = array()) { - // Include deleted instances if specified either in the $include_additional - // or the $conditions parameters. - $include_deleted = (isset($include_additional['include_deleted']) && $include_additional['include_deleted']) || (isset($conditions['deleted']) && $conditions['deleted']); - - // Pass include_deleted to the $conditions array. - $conditions['include_deleted'] = $include_deleted; - - return entity_load_multiple_by_properties('field_instance', $conditions); -} - /** * Adds form elements for all fields for an entity to a form structure. * @@ -755,75 +495,3 @@ function field_attach_view(EntityInterface $entity, EntityViewDisplayInterface $ return $output; } - -/** - * Returns the field items in the language they currently would be displayed. - * - * @param \Drupal\Core\Entity\EntityInterface $entity - * The entity containing the data to be displayed. - * @param $field_name - * The field to be displayed. - * @param $langcode - * (optional) The language code $entity->{$field_name} has to be displayed in. - * Defaults to the current language. - * - * @return - * An array with available field items keyed by delta. - * - * @deprecated as of Drupal 8.0. Use - * $entity->getTranslation($langcode)->{$field_name} - */ -function field_get_items(EntityInterface $entity, $field_name, $langcode = NULL) { - return \Drupal::entityManager()->getTranslationFromContext($entity, $langcode)->{$field_name}; -} - -/** - * Helper function to get the default value for a field on an entity. - * - * @param \Drupal\Core\Entity\EntityInterface $entity - * The entity for the operation. - * @param $field - * The field structure. - * @param $instance - * The instance structure. - * @param $langcode - * The field language to fill-in with the default value. - * - * @return array - * The default value for the field. - * - * @deprecated as of Drupal 8.0. Use - * $instance->getDefaultValue($entity) - */ -function field_get_default_value(EntityInterface $entity, $field, $instance, $langcode = NULL) { - return $instance->getDefaultValue($entity); -} - -/** - * Determines whether the user has access to a given field. - * - * @param string $op - * The operation to be performed. Possible values: - * - edit - * - view - * @param \Drupal\field\FieldInterface $field - * The field on which the operation is to be performed. - * @param $entity_type - * The type of $entity; for example, 'node' or 'user'. - * @param $entity - * (optional) The entity for the operation. - * @param $account - * (optional) The account to check, if not given use currently logged in user. - * - * @return - * TRUE if the operation is allowed; FALSE if the operation is denied. - * - * @deprecated as of Drupal 8.0. Use - * Drupal\Core\Entity\EntityAccessControllerInterface::fieldAccess() - */ -function field_access($op, FieldInterface $field, $entity_type, $entity = NULL, $account = NULL) { - $access_controller = \Drupal::entityManager()->getAccessController($entity_type); - - $items = $entity ? $entity->get($field->id()) : NULL; - return $access_controller->fieldAccess($op, $field, $account, $items); -} diff --git a/core/modules/field/lib/Drupal/field/Entity/Field.php b/core/modules/field/lib/Drupal/field/Entity/Field.php index 098d83fbff5..b127979a2aa 100644 --- a/core/modules/field/lib/Drupal/field/Entity/Field.php +++ b/core/modules/field/lib/Drupal/field/Entity/Field.php @@ -515,10 +515,10 @@ class Field extends ConfigEntityBase implements FieldInterface { * {@inheritdoc} */ public function getSettings() { - // @todo field_info_field_types() calls _field_info_collate_types() which - // maintains its own static cache. However, do some CPU and memory - // profiling to see if it's worth statically caching $field_type_info, or - // the default field and instance settings, within $this. + // @todo FieldTypePluginManager maintains its own static cache. However, do + // some CPU and memory profiling to see if it's worth statically caching + // $field_type_info, or the default field and instance settings, within + // $this. $field_type_info = \Drupal::service('plugin.manager.field.field_type')->getDefinition($this->type); $settings = $this->settings + $field_type_info['settings'] + $field_type_info['instance_settings'];