diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 82fec7a..af25647 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -987,7 +987,7 @@ public function onEntityTypeCreate(EntityTypeInterface $entity_type) { } $this->setLastInstalledDefinition($entity_type); - if ($storage instanceof FieldableEntityStorageInterface) { + if ($entity_type->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface')) { $this->setLastInstalledFieldStorageDefinitions($entity_type_id, $this->getFieldStorageDefinitions($entity_type_id)); } } diff --git a/core/modules/comment/comment.views.inc b/core/modules/comment/comment.views.inc index b6b6955..cdd7ec0 100644 --- a/core/modules/comment/comment.views.inc +++ b/core/modules/comment/comment.views.inc @@ -22,7 +22,7 @@ function comment_views_data_alter(&$data) { // Provide a integration for each entity type except comment. foreach (\Drupal::entityManager()->getDefinitions() as $entity_type_id => $entity_type) { - if ($entity_type_id == 'comment' || !$entity_type->getBaseTable()) { + if ($entity_type_id == 'comment' || !$entity_type->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface') || !$entity_type->getBaseTable()) { continue; } $fields = \Drupal::service('comment.manager')->getFields($entity_type_id); diff --git a/core/modules/comment/src/CommentTypeForm.php b/core/modules/comment/src/CommentTypeForm.php index 93a64f6..3808657 100644 --- a/core/modules/comment/src/CommentTypeForm.php +++ b/core/modules/comment/src/CommentTypeForm.php @@ -92,7 +92,9 @@ public function form(array $form, FormStateInterface $form_state) { if ($comment_type->isNew()) { $options = array(); foreach ($this->entityManager->getDefinitions() as $entity_type) { - if ($entity_type instanceof ContentEntityTypeInterface) { + // Only expose entities that have field UI enabled, only those can + // get comment fields added in the UI. + if ($entity_type->get('field_ui_base_route')) { $options[$entity_type->id()] = $entity_type->getLabel(); } } diff --git a/core/modules/comment/src/CommentViewsData.php b/core/modules/comment/src/CommentViewsData.php index b7c09ed..ee4f1ce 100644 --- a/core/modules/comment/src/CommentViewsData.php +++ b/core/modules/comment/src/CommentViewsData.php @@ -386,7 +386,7 @@ public function getViewsData() { // Provide a relationship for each entity type except comment. foreach ($entities_types as $type => $entity_type) { - if ($type == 'comment' || !$entity_type->getBaseTable()) { + if ($type == 'comment' || !$entity_type->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface') || !$entity_type->getBaseTable()) { continue; } if ($fields = \Drupal::service('comment.manager')->getFields($type)) { @@ -465,7 +465,7 @@ public function getViewsData() { // Provide a relationship for each entity type except comment. foreach ($entities_types as $type => $entity_type) { - if ($type == 'comment' || !$entity_type->getBaseTable()) { + if ($type == 'comment' || !$entity_type->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface') || !$entity_type->getBaseTable()) { continue; } // This relationship does not use the 'field id' column, if the entity has diff --git a/core/modules/config_translation/config_translation.module b/core/modules/config_translation/config_translation.module index ee88d86..956861a 100644 --- a/core/modules/config_translation/config_translation.module +++ b/core/modules/config_translation/config_translation.module @@ -121,7 +121,7 @@ function config_translation_config_translation_info(&$info) { } // Make sure entity type has field UI enabled and has a base route. - if ($entity_type->get('field_ui_ui_base_route') && !empty($base_route)) { + if ($entity_type->get('field_ui_base_route') && !empty($base_route)) { $info[$entity_type_id . '_fields'] = array( 'base_route_name' => 'field_ui.field_edit_' . $entity_type_id, 'entity_type' => 'field_config', diff --git a/core/modules/content_translation/src/ContentTranslationHandler.php b/core/modules/content_translation/src/ContentTranslationHandler.php index b619036..19ba5a1 100644 --- a/core/modules/content_translation/src/ContentTranslationHandler.php +++ b/core/modules/content_translation/src/ContentTranslationHandler.php @@ -100,6 +100,7 @@ public function entityFormAlter(array &$form, FormStateInterface $form_state, En unset($translations[$form_langcode]); } $is_translation = !$form_object->isDefaultFormLangcode($form_state); + debug($translations, 'translations'); $has_translations = count($translations) > 1; // Adjust page title to specify the current language being edited, if we @@ -117,6 +118,8 @@ public function entityFormAlter(array &$form, FormStateInterface $form_state, En // Display source language selector only if we are creating a new // translation and there are at least two translations available. + debug($has_translations, 'has'); + debug($new_translation, 'new'); if ($has_translations && $new_translation) { $form['source_langcode'] = array( '#type' => 'details', diff --git a/core/modules/field/field.module b/core/modules/field/field.module index cc06269..12632e0 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -6,6 +6,7 @@ use Drupal\Core\Config\ConfigImporter; use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Core\Entity\FieldableEntityStorageInterface; use Drupal\Core\Extension\Extension; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Routing\RouteMatchInterface; @@ -152,38 +153,42 @@ function field_system_info_alter(&$info, Extension $file, $type) { * Implements hook_entity_field_storage_info(). */ function field_entity_field_storage_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type) { - // Query by filtering on the ID as this is more efficient than filtering - // on the entity_type property directly. - $ids = \Drupal::entityQuery('field_storage_config') - ->condition('id', $entity_type->id() . '.', 'STARTS_WITH') - ->execute(); + if (\Drupal::entityManager()->getStorage($entity_type->id()) instanceof FieldableEntityStorageInterface) { + // Query by filtering on the ID as this is more efficient than filtering + // on the entity_type property directly. + $ids = \Drupal::entityQuery('field_storage_config') + ->condition('id', $entity_type->id() . '.', 'STARTS_WITH') + ->execute(); + // Fetch all fields and key them by field name. + $field_storages = entity_load_multiple('field_storage_config', $ids); + $result = array(); + foreach ($field_storages as $field_storage) { + $result[$field_storage->getName()] = $field_storage; + } - // Fetch all fields and key them by field name. - $field_storages = entity_load_multiple('field_storage_config', $ids); - $result = array(); - foreach ($field_storages as $field_storage) { - $result[$field_storage->getName()] = $field_storage; + return $result; } - return $result; } /** * Implements hook_entity_bundle_field_info(). */ function field_entity_bundle_field_info(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) { - // Query by filtering on the ID as this is more efficient than filtering - // on the entity_type property directly. - $ids = \Drupal::entityQuery('field_config') - ->condition('id', $entity_type->id() . '.' . $bundle . '.', 'STARTS_WITH') - ->execute(); + if (\Drupal::entityManager()->getStorage($entity_type->id()) instanceof FieldableEntityStorageInterface) { + // Query by filtering on the ID as this is more efficient than filtering + // on the entity_type property directly. + $ids = \Drupal::entityQuery('field_config') + ->condition('id', $entity_type->id() . '.' . $bundle . '.', 'STARTS_WITH') + ->execute(); + // Fetch all fields and key them by field name. + $field_configs = entity_load_multiple('field_config', $ids); + $result = array(); + foreach ($field_configs as $field_instance) { + $result[$field_instance->getName()] = $field_instance; + } - // Fetch all fields and key them by field name. - $field_configs = entity_load_multiple('field_config', $ids); - $result = array(); - foreach ($field_configs as $field_instance) { - $result[$field_instance->getName()] = $field_instance; + return $result; } - return $result; } /** diff --git a/core/modules/field_ui/src/Controller/EntityDisplayModeController.php b/core/modules/field_ui/src/Controller/EntityDisplayModeController.php index a42a591..88ffd4e 100644 --- a/core/modules/field_ui/src/Controller/EntityDisplayModeController.php +++ b/core/modules/field_ui/src/Controller/EntityDisplayModeController.php @@ -24,7 +24,7 @@ class EntityDisplayModeController extends ControllerBase { public function viewModeTypeSelection() { $entity_types = array(); foreach ($this->entityManager()->getDefinitions() as $entity_type_id => $entity_type) { - if ($entity_type->hasViewBuilderClass()) { + if ($entity_type->get('field_ui_base_route') && $entity_type->hasViewBuilderClass()) { $entity_types[$entity_type_id] = array( 'title' => $entity_type->getLabel(), 'url' => new Url('field_ui.entity_view_mode_add_type', array('entity_type_id' => $entity_type_id)), @@ -47,7 +47,7 @@ public function viewModeTypeSelection() { public function formModeTypeSelection() { $entity_types = array(); foreach ($this->entityManager()->getDefinitions() as $entity_type_id => $entity_type) { - if ($entity_type->hasFormClasses()) { + if ($entity_type->get('field_ui_base_route') && $entity_type->hasFormClasses()) { $entity_types[$entity_type_id] = array( 'title' => $entity_type->getLabel(), 'url' => new Url('field_ui.entity_form_mode_add_type', array('entity_type_id' => $entity_type_id)), diff --git a/core/modules/field_ui/src/EntityDisplayModeListBuilder.php b/core/modules/field_ui/src/EntityDisplayModeListBuilder.php index dd2ed75..2a73834 100644 --- a/core/modules/field_ui/src/EntityDisplayModeListBuilder.php +++ b/core/modules/field_ui/src/EntityDisplayModeListBuilder.php @@ -142,7 +142,7 @@ public function render() { * doesn't has the correct controller. */ protected function isValidEntity($entity_type) { - return $this->entityTypes[$entity_type]->hasViewBuilderClass(); + return $this->entityTypes[$entity_type]->get('field_ui_base_route') && $this->entityTypes[$entity_type]->hasViewBuilderClass(); } } diff --git a/core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php b/core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php index c71ea69..cd207de 100644 --- a/core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php +++ b/core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php @@ -49,7 +49,7 @@ public function validate(array $form, FormStateInterface $form_state) { */ protected function prepareEntity() { $definition = $this->entityManager->getDefinition($this->targetEntityTypeId); - if (!$definition->hasViewBuilderClass()) { + if (!$definition->get('field_ui_base_route') || !$definition->hasViewBuilderClass()) { throw new NotFoundHttpException(); } diff --git a/core/modules/field_ui/src/Form/EntityFormModeAddForm.php b/core/modules/field_ui/src/Form/EntityFormModeAddForm.php index 6aa82ad..d7864ca 100644 --- a/core/modules/field_ui/src/Form/EntityFormModeAddForm.php +++ b/core/modules/field_ui/src/Form/EntityFormModeAddForm.php @@ -19,7 +19,7 @@ class EntityFormModeAddForm extends EntityDisplayModeAddForm { */ protected function prepareEntity() { $definition = $this->entityManager->getDefinition($this->targetEntityTypeId); - if (!$definition->hasFormClasses()) { + if (!$definition->get('field_ui_base_route') || !$definition->hasFormClasses()) { throw new NotFoundHttpException(); } diff --git a/core/modules/shortcut/src/Entity/Shortcut.php b/core/modules/shortcut/src/Entity/Shortcut.php index a3e15e7d..df96d6f 100644 --- a/core/modules/shortcut/src/Entity/Shortcut.php +++ b/core/modules/shortcut/src/Entity/Shortcut.php @@ -45,8 +45,7 @@ * "delete-form" = "entity.shortcut.delete_form", * "edit-form" = "entity.shortcut.canonical", * }, - * bundle_entity_type = "shortcut_set", - * field_ui_base_route = "entity.shortcut.canonical", + * bundle_entity_type = "shortcut_set" * ) */ class Shortcut extends ContentEntityBase implements ShortcutInterface { diff --git a/core/modules/shortcut/src/Tests/ShortcutTranslationUITest.php b/core/modules/shortcut/src/Tests/ShortcutTranslationUITest.php index 1627b60..453e465 100644 --- a/core/modules/shortcut/src/Tests/ShortcutTranslationUITest.php +++ b/core/modules/shortcut/src/Tests/ShortcutTranslationUITest.php @@ -35,7 +35,6 @@ class ShortcutTranslationUITest extends ContentTranslationUITest { protected function setUp() { $this->entityTypeId = 'shortcut'; $this->bundle = 'default'; - $this->fieldName = 'title'; parent::setUp(); } @@ -54,6 +53,13 @@ protected function createEntity($values, $langcode, $bundle_name = NULL) { return parent::createEntity($values, $langcode, $bundle_name); } + /** + * {@inheritdoc} + */ + protected function getNewEntityValues($langcode) { + return array('title' => array(array('value' => $this->randomMachineName()))) + parent::getNewEntityValues($langcode); + } + protected function doTestBasicTranslation() { parent::doTestBasicTranslation();