diff --git a/core/modules/entity_reference/entity_reference.module b/core/modules/entity_reference/entity_reference.module index 03a3067..4578dc8 100644 --- a/core/modules/entity_reference/entity_reference.module +++ b/core/modules/entity_reference/entity_reference.module @@ -199,6 +199,38 @@ function entity_reference_field_settings_form($field, $instance, $has_data) { } /** + * Implements hook_field_update_field(). + * + * Reset the instance handler settings, when the target-type is changed. + */ +function entity_reference_field_update_field($field, $prior_field, $has_data) { + if ($field['type'] != 'entity_reference') { + // Not an entity reference field. + return; + } + + if ($field['settings']['target_type'] == $prior_field['settings']['target_type']) { + // Target type didn't change. + return; + } + + if (empty($field['bundles'])) { + // Field has no instances. + return; + } + + $field_name = $field['field_name']; + + foreach ($field['bundles'] as $entity_type => $bundles) { + foreach ($bundles as $bundle) { + $instance = field_info_instance($entity_type, $field_name, $bundle); + $instance['settings']['handler_settings'] = array(); + field_update_instance($instance); + } + } +} + +/** * Implements hook_field_instance_settings_form(). */ function entity_reference_field_instance_settings_form($field, $instance, $form_state) { diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/entity_reference/selection/SelectionBase.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/entity_reference/selection/SelectionBase.php index 59c6634..a7a9006 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/entity_reference/selection/SelectionBase.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/entity_reference/selection/SelectionBase.php @@ -157,12 +157,6 @@ public static function settingsForm(&$field, &$instance) { ); } - $form['auto_create'] = array( - '#type' => 'checkbox', - '#title' => t("Create referenced entities if they don't already exist"), - '#default_value' => $instance['settings']['handler_settings']['auto_create'], - ); - return $form; } diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceLabelFormatter.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceLabelFormatter.php index dce40e2..3b5d611 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceLabelFormatter.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceLabelFormatter.php @@ -24,7 +24,7 @@ * "entity_reference" * }, * settings = { - * "link" = FALSE + * "link" = TRUE * } * ) */ diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/entity_reference/selection/TermSelection.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/entity_reference/selection/TermSelection.php index 5c58165..c99c6c5 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/entity_reference/selection/TermSelection.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/entity_reference/selection/TermSelection.php @@ -34,6 +34,23 @@ public function entityQueryAlter(SelectInterface $query) { } /** + * Overrides SelectionBase::settingsForm(). + */ + public static function settingsForm(&$field, &$instance) { + $form = parent::settingsForm($field, $instance); + + // @todo: Currently allow auto-create only on taxonomy terms. + $form['auto_create'] = array( + '#type' => 'checkbox', + '#title' => t("Create referenced entities if they don't already exist"), + '#default_value' => $instance['settings']['handler_settings']['auto_create'], + ); + return $form; + + } + + + /** * Overrides SelectionBase::getReferencableEntities(). */ public function getReferencableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) { diff --git a/core/modules/views/lib/Drupal/views/Plugin/entity_reference/selection/ViewsSelection.php b/core/modules/views/lib/Drupal/views/Plugin/entity_reference/selection/ViewsSelection.php index 603d6df..ce8a7d7 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/entity_reference/selection/ViewsSelection.php +++ b/core/modules/views/lib/Drupal/views/Plugin/entity_reference/selection/ViewsSelection.php @@ -55,7 +55,7 @@ public static function settingsForm(&$field, &$instance) { foreach ($displays as $data) { list($view, $display_id) = $data; if ($view->storage->get('base_table') == $entity_info['base_table']) { - $name = $view->storage->get('name'); + $name = $view->storage->get('id'); $display = $view->storage->get('display'); $options[$name . ':' . $display_id] = $name . ' - ' . $display[$display_id]['display_title']; } @@ -119,12 +119,10 @@ public static function settingsForm(&$field, &$instance) { protected function initializeView($match = NULL, $match_operator = 'CONTAINS', $limit = 0, $ids = NULL) { $view_name = $this->instance['settings']['handler_settings']['view']['view_name']; $display_name = $this->instance['settings']['handler_settings']['view']['display_name']; - $arguments = $this->instance['settings']['handler_settings']['view']['arguments']; - $entity_type = $this->field['settings']['target_type']; // Check that the view is valid and the display still exists. $this->view = views_get_view($view_name); - if (!$this->view || !$this->view->access($display_name)) { + if (!$this->view || !$this->view->access($display_name)) { throw new \RuntimeException(t('The view %view_name is no longer eligible for the %field_name field.', array('%view_name' => $view_name, '%field_name' => $this->instance['label']))); } $this->view->setDisplay($display_name);