diff --git a/core/lib/Drupal/Core/Entity/ContentEntityInterface.php b/core/lib/Drupal/Core/Entity/ContentEntityInterface.php index 57090dd..137e6e3 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityInterface.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityInterface.php @@ -18,11 +18,11 @@ /** * Marks the translation identified by the given language code as existing. * - * @todo Remove this as soon as translation metadata have been converted to - * regular fields. - * * @param string $langcode * The language code identifying the translation to be initialized. + * + * @todo Remove this as soon as translation metadata have been converted to + * regular fields. */ public function initTranslation($langcode); diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index 9732fd4..a19b4af 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -197,8 +197,6 @@ public function access($operation = 'view', AccountInterface $account = NULL) { * {@inheritdoc} */ public function language() { - // @todo: Replace by EntityNG implementation once all entity types have been - // converted to use the entity field API. $language = language_load($this->langcode); if (!$language) { // Make sure we return a proper language object. @@ -208,41 +206,6 @@ public function language() { } /** - * Implements \Drupal\Core\TypedData\TranslatableInterface::getTranslationLanguages(). - */ - public function getTranslationLanguages($include_default = TRUE) { - // @todo: Replace by EntityNG implementation once all entity types have been - // converted to use the entity field API. - $default_language = $this->language(); - $languages = array($default_language->id => $default_language); - $entity_info = $this->entityInfo(); - if ($entity_info['fieldable']) { - // Go through translatable properties and determine all languages for - // which translated values are available. - foreach (field_info_instances($this->entityType, $this->bundle()) as $field_name => $instance) { - $field = field_info_field($field_name); - if (field_is_translatable($this->entityType, $field) && isset($this->$field_name)) { - foreach (array_filter($this->$field_name) as $langcode => $value) { - $languages[$langcode] = TRUE; - } - } - } - $languages = array_intersect_key(language_list(Language::STATE_ALL), $languages); - } - - if (empty($include_default)) { - unset($languages[$default_language->id]); - } - - return $languages; - } - - /** - * {@inheritdoc} - */ - public function getTranslation($langcode) { } - - /** * Implements \Drupal\Core\Entity\EntityInterface::save(). */ public function save() { diff --git a/core/lib/Drupal/Core/Entity/EntityFormController.php b/core/lib/Drupal/Core/Entity/EntityFormController.php index 5fa494c..a6a329b 100644 --- a/core/lib/Drupal/Core/Entity/EntityFormController.php +++ b/core/lib/Drupal/Core/Entity/EntityFormController.php @@ -162,15 +162,9 @@ public function form(array $form, array &$form_state) { // If the form did not specify otherwise, default to keeping the existing // language of the entity or defaulting to the site default language for // new entities. - if (!$entity->isNew()) { - $langcode = $entity->language()->id; - } - else { - $langcode = language_default()->id; - } $form['langcode'] = array( '#type' => 'value', - '#value' => $langcode, + '#value' => !$entity->isNew() ? $entity->getUntranslated()->language()->id : language_default()->id, ); } return $form; @@ -325,24 +319,10 @@ public function delete(array $form, array &$form_state) { } /** - * Implements \Drupal\Core\Entity\EntityFormControllerInterface::getFormLangcode(). + * {@inheritdoc} */ public function getFormLangcode(array $form_state) { - $entity = $this->entity; - - if (!empty($form_state['langcode'])) { - $langcode = $form_state['langcode']; - } - - // If the site is not multilingual or no translation for the given form - // language is available, fall back to the entity language. - if (!empty($langcode)) { - return $langcode; - } - else { - // Fall back to the current language of the entity. - return $entity->language()->id; - } + return $this->entity->language()->id; } /** diff --git a/core/lib/Drupal/Core/Entity/EntityStorageControllerBase.php b/core/lib/Drupal/Core/Entity/EntityStorageControllerBase.php index 988afa7..c1ddbe4 100644 --- a/core/lib/Drupal/Core/Entity/EntityStorageControllerBase.php +++ b/core/lib/Drupal/Core/Entity/EntityStorageControllerBase.php @@ -140,35 +140,15 @@ protected function cacheSet($entities) { * {@inheritdoc} */ public function invokeFieldMethod($method, EntityInterface $entity) { - foreach (array_keys($entity->getTranslationLanguages()) as $langcode) { - // @todo getTranslation() only works on NG entities. Remove the condition - // and the second code branch when all core entity types are converted. - if ($translation = $entity->getTranslation($langcode)) { - foreach ($translation as $field_name => $field) { - $field->$method(); - } - } - else { - // For BC entities, iterate through fields and instantiate NG items - // objects manually. - $definitions = \Drupal::entityManager()->getFieldDefinitions($entity->entityType(), $entity->bundle()); - foreach ($definitions as $field_name => $definition) { - if (!empty($definition['configurable'])) { - // Create the items object. - $itemsBC = isset($entity->{$field_name}[$langcode]) ? $entity->{$field_name}[$langcode] : array(); - // @todo Exception : this calls setValue(), tries to set the - // 'formatted' property. For now, this is worked around by - // commenting out the Exception in TextProcessed::setValue(). - $items = \Drupal::typedData()->create($definition, $itemsBC, $field_name, $entity); - $items->$method(); + // Only act on content entities. + if (!($entity instanceof ContentEntityInterface)) { + return; + } - // Put back the items values in the entity. - $itemsBC = $items->getValue(TRUE); - if ($itemsBC !== array() || isset($entity->{$field_name}[$langcode])) { - $entity->{$field_name}[$langcode] = $itemsBC; - } - } - } + foreach (array_keys($entity->getTranslationLanguages()) as $langcode) { + $translation = $entity->getTranslation($langcode); + foreach ($translation as $field) { + $field->$method(); } } } @@ -177,56 +157,27 @@ public function invokeFieldMethod($method, EntityInterface $entity) { * {@inheritdoc} */ public function invokeFieldItemPrepareCache(EntityInterface $entity) { + // Only act on content entities. + if (!($entity instanceof ContentEntityInterface)) { + return; + } foreach (array_keys($entity->getTranslationLanguages()) as $langcode) { - // @todo getTranslation() only works on NG entities. Remove the condition - // and the second code branch when all core entity types are converted. - if ($translation = $entity->getTranslation($langcode)) { - foreach ($translation->getPropertyDefinitions() as $property => $definition) { - $type_definition = \Drupal::typedData()->getDefinition($definition['type']); - // Only create the item objects if needed. - if (is_subclass_of($type_definition['class'], '\Drupal\Core\Entity\Field\PrepareCacheInterface') - // Prevent legacy field types from skewing performance too much by - // checking the existence of the legacy function directly, instead - // of making LegacyConfigFieldItem implement PrepareCacheInterface. - // @todo Remove once all core field types have been converted (see - // http://drupal.org/node/2014671). - || (is_subclass_of($type_definition['class'], '\Drupal\field\Plugin\field\field_type\LegacyConfigFieldItem') && function_exists($type_definition['provider'] . '_field_load'))) { - - // Call the prepareCache() method directly on each item - // individually. - foreach ($translation->get($property) as $item) { - $item->prepareCache(); - } - } - } - } - else { - // For BC entities, iterate through the fields and instantiate NG items - // objects manually. - $definitions = \Drupal::entityManager()->getFieldDefinitions($entity->entityType(), $entity->bundle()); - foreach ($definitions as $field_name => $definition) { - if (!empty($definition['configurable'])) { - $type_definition = \Drupal::typedData()->getDefinition($definition['type']); - // Only create the item objects if needed. - if (is_subclass_of($type_definition['class'], '\Drupal\Core\Entity\Field\PrepareCacheInterface') - // @todo Remove once all core field types have been converted - // (see http://drupal.org/node/2014671). - || (is_subclass_of($type_definition['class'], '\Drupal\field\Plugin\field\field_type\LegacyConfigFieldItem') && function_exists($type_definition['provider'] . '_field_load'))) { - - // Create the items object. - $items = isset($entity->{$field_name}[$langcode]) ? $entity->{$field_name}[$langcode] : array(); - $itemsNG = \Drupal::typedData()->create($definition, $items, $field_name, $entity); - - foreach ($itemsNG as $item) { - $item->prepareCache(); - } - - // Put back the items values in the entity. - $items = $itemsNG->getValue(TRUE); - if ($items !== array() || isset($entity->{$field_name}[$langcode])) { - $entity->{$field_name}[$langcode] = $items; - } - } + $translation = $entity->getTranslation($langcode); + foreach ($translation->getPropertyDefinitions() as $property => $definition) { + $type_definition = \Drupal::typedData()->getDefinition($definition['type']); + // Only create the item objects if needed. + if (is_subclass_of($type_definition['class'], '\Drupal\Core\Entity\Field\PrepareCacheInterface') + // Prevent legacy field types from skewing performance too much by + // checking the existence of the legacy function directly, instead + // of making LegacyConfigFieldItem implement PrepareCacheInterface. + // @todo Remove once all core field types have been converted (see + // http://drupal.org/node/2014671). + || (is_subclass_of($type_definition['class'], '\Drupal\field\Plugin\field\field_type\LegacyConfigFieldItem') && function_exists($type_definition['provider'] . '_field_load'))) { + + // Call the prepareCache() method directly on each item + // individually. + foreach ($translation->get($property) as $item) { + $item->prepareCache(); } } } @@ -240,6 +191,10 @@ public function invokeFieldItemPrepareCache(EntityInterface $entity) { * The entity being saved. */ protected function invokeTranslationHooks(EntityInterface $entity) { + // Only act on content entities. + if (!($entity instanceof ContentEntityInterface)) { + return; + } $translations = $entity->getTranslationLanguages(FALSE); $original_translations = $entity->original->getTranslationLanguages(FALSE); $all_translations = array_keys($translations + $original_translations); diff --git a/core/modules/editor/editor.module b/core/modules/editor/editor.module index fd95b0f..81dd624 100644 --- a/core/modules/editor/editor.module +++ b/core/modules/editor/editor.module @@ -5,7 +5,7 @@ * Adds bindings for client-side "text editors" to text formats. */ -use Drupal\file\Entity\File; +use Drupal\Core\Entity\ContentEntityInterface; use Drupal\editor\Entity\Editor; use Drupal\Component\Utility\NestedArray; use Drupal\Core\Entity\EntityInterface; @@ -392,6 +392,10 @@ function editor_pre_render_format($element) { * Implements hook_entity_insert(). */ function editor_entity_insert(EntityInterface $entity) { + // Only act on content entities. + if (!($entity instanceof ContentEntityInterface)) { + return; + } $referenced_files_by_field = _editor_get_file_uuids_by_field($entity); foreach ($referenced_files_by_field as $field => $uuids) { _editor_record_file_usage($uuids, $entity); @@ -402,6 +406,11 @@ function editor_entity_insert(EntityInterface $entity) { * Implements hook_entity_update(). */ function editor_entity_update(EntityInterface $entity) { + // Only act on content entities. + if (!($entity instanceof ContentEntityInterface)) { + return; + } + // On new revisions, all files are considered to be a new usage and no // deletion of previous file usages are necessary. if (!empty($entity->original) && $entity->getRevisionId() != $entity->original->getRevisionId()) { diff --git a/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php b/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php index 651f471..aa65f56 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php @@ -793,13 +793,6 @@ public function &getDisplay($display_id) { } /** - * Implements \IteratorAggregate::getIterator(). - */ - public function getIterator() { - return $this->storage->getIterator(); - } - - /** * Implements \Drupal\Core\Entity\EntityInterface::id(). */ public function id() { @@ -906,48 +899,6 @@ public function access($operation = 'view', AccountInterface $account = NULL) { } /** - * Implements \Drupal\Core\TypedData\ComplexDataInterface::isEmpty)(). - */ - public function isEmpty() { - return $this->storage->isEmpty(); - } - - /** - * Implements \Drupal\Core\TypedData\ComplexDataInterface::getPropertyValues(). - */ - public function getPropertyValues() { - return $this->storage->getPropertyValues(); - } - - /** - * Implements \Drupal\Core\TypedData\ComplexDataInterface::getPropertyDefinitions(). - */ - public function getPropertyDefinitions() { - return $this->storage->getPropertyDefinitions(); - } - - /** - * Implements \Drupal\Core\TypedData\ComplexDataInterface::getPropertyDefinition(). - */ - public function getPropertyDefinition($name) { - return $this->storage->getPropertyDefinition($name); - } - - /** - * Implements \Drupal\Core\TypedData\ComplexDataInterface::setPropertyValues(). - */ - public function setPropertyValues($values) { - return $this->storage->setPropertyValues($values); - } - - /** - * Implements \Drupal\Core\TypedData\ComplexDataInterface::getProperties(). - */ - public function getProperties($include_computed = FALSE) { - return $this->storage->getProperties($include_computed); - } - - /** * Implements \Drupal\Core\Config\Entity\ConfigEntityInterface::enable(). */ public function enable() { @@ -1188,13 +1139,4 @@ public function uriRelationships() { return $this->storage->uriRelationships(); } - /** - * {@inheritdoc} - */ - public static function baseFieldDefinitions($entity_type) { - // @todo: This class is not directly defined as an entity type and does - // not have base definitions but has to implement this method. Remove in - // https://drupal.org/node/2004244. - return array(); - } }