diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/entity_reference/selection/CommentSelection.php b/core/modules/comment/lib/Drupal/comment/Plugin/entity_reference/selection/CommentSelection.php index 8010f19..42f6a32 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/entity_reference/selection/CommentSelection.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/entity_reference/selection/CommentSelection.php @@ -16,11 +16,11 @@ * Provides specific access control for the comment entity type. * * @Plugin( - * id = "base_comment", - * module = "entity_reference", + * id = "comment_default", + * module = "comment", * label = @Translation("Comment selection"), * entity_types = {"comment"}, - * group = "base", + * group = "default", * weight = 1 * ) */ diff --git a/core/modules/entity_reference/entity_reference.module b/core/modules/entity_reference/entity_reference.module index 6cf9afa..053e2ee 100644 --- a/core/modules/entity_reference/entity_reference.module +++ b/core/modules/entity_reference/entity_reference.module @@ -23,7 +23,7 @@ function entity_reference_field_info() { ), 'instance_settings' => array( // The selection handler for this instance. - 'handler' => 'base', + 'handler' => 'default', // The handler settings. 'handler_settings' => array(), ), @@ -83,6 +83,8 @@ function entity_reference_menu() { /** * Gets the selection handler for a given entity_reference field. + * + * @return \Drupal\entity_reference\Plugin\Type\Selection\SelectionInterface */ function entity_reference_get_selection_handler($field, $instance, EntityInterface $entity = NULL) { $options = array( @@ -130,7 +132,7 @@ function entity_reference_field_presave(EntityInterface $entity, $field, $instan $label_key => $item['label'], $bundle_key => $bundle, // @todo: Use wrapper to get the user if exists or needed. - 'uid' => !empty($entity->uid) ? $entity->uid : $user->uid, + 'uid' => isset($entity->uid) ? $entity->uid : $user->uid, ); $target_entity = entity_create($target_type, $values); $target_entity->save(); @@ -146,7 +148,7 @@ function entity_reference_field_presave(EntityInterface $entity, $field, $instan function entity_reference_field_validate(EntityInterface $entity = NULL, $field, $instance, $langcode, $items, &$errors) { $ids = array(); foreach ($items as $delta => $item) { - if (!entity_reference_field_is_empty($item, $field) && $item['target_id'] !== 'auto_create') { + if ($item['target_id'] !== 'auto_create' && !entity_reference_field_is_empty($item, $field)) { $ids[$item['target_id']] = $delta; } } @@ -197,41 +199,13 @@ function entity_reference_field_settings_form($field, $instance, $has_data) { /** * Implements hook_field_instance_settings_form(). - * - * The field settings infrastructure is not AJAX enabled by default, - * because it doesn't pass over the $form_state. - * Build the whole form into a #process in which we actually have access - * to the form state. - */ -function entity_reference_field_instance_settings_form($field, $instance) { - $form['entity_reference_wrapper'] = array( - '#type' => 'container', - '#attached' => array( - 'css' => array(drupal_get_path('module', 'entity_reference') . '/css/entity_reference.admin.css'), - ), - '#process' => array( - '_entity_reference_field_instance_settings_process', - '_entity_reference_field_instance_settings_ajax_process', - ), - '#element_validate' => array('_entity_reference_field_instance_settings_validate'), - '#field' => $field, - '#instance' => $instance->definition, - ); - return $form; -} - -/** - * Render API callback: Processes the field settings form and allows access to - * the form state. - * - * @see entity_reference_field_instance_settings_form() */ -function _entity_reference_field_instance_settings_process($form, $form_state) { - $field = isset($form_state['entity_reference']['field']) ? $form_state['entity_reference']['field'] : $form['#field']; - $instance = isset($form_state['entity_reference']['instance']) ? $form_state['entity_reference']['instance'] : $form['#instance']; +function entity_reference_field_instance_settings_form($field, $instance, $form_state) { + $field = isset($form_state['entity_reference']['field']) ? $form_state['entity_reference']['field'] : $field; + $instance = isset($form_state['entity_reference']['instance']) ? $form_state['entity_reference']['instance'] : $instance; $settings = $instance['settings']; - $settings += array('handler' => 'base'); + $settings += array('handler' => 'default'); // Get all selection plugins for this entity type. $selection_plugins = drupal_container()->get('plugin.manager.entity_reference.selection')->getSelectionGroups($field['settings']['target_type']); @@ -247,6 +221,18 @@ function _entity_reference_field_instance_settings_process($form, $form_state) { } } + $form = array( + '#type' => 'container', + '#attached' => array( + 'css' => array(drupal_get_path('module', 'entity_reference') . '/css/entity_reference.admin.css'), + ), + '#process' => array( + '_entity_reference_field_instance_settings_ajax_process', + ), + '#element_validate' => array('_entity_reference_field_instance_settings_validate'), + '#field' => $field, + '#instance' => $instance, + ); $form['handler'] = array( '#type' => 'details', '#title' => t('Reference type'), @@ -325,11 +311,6 @@ function _entity_reference_field_instance_settings_ajax_process_element(&$elemen function _entity_reference_form_process_merge_parent($element) { $parents = $element['#parents']; array_pop($parents); - // For the 'Selection' fieldset, we need to go one more level above - // because of our extra container. - if (isset($element['#title']) && $element['#title'] == t('Reference type')) { - array_pop($parents); - } $element['#parents'] = $parents; return $element; } diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Type/Selection/SelectionInterface.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Type/Selection/SelectionInterface.php index 49ad461..7e41792 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Type/Selection/SelectionInterface.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Type/Selection/SelectionInterface.php @@ -30,6 +30,9 @@ public function getReferencableEntities($match = NULL, $match_operator = 'CONTAI /** * Counts entities that are referencable by a given field. + * + * @return int + * The number of referencable entities. */ public function countReferencableEntities($match = NULL, $match_operator = 'CONTAINS'); @@ -49,7 +52,8 @@ public function validateReferencableEntities(array $ids); * @param array $element * The form element to set a form error. * @param boolean $strict - * If TRUE, and an element is not found issue a form error. + * Whether to trigger a form error if an element from $input (eg. an entity) + * is not found. Defaults to TRUE. * * @return integer|null * Value of a matching entity ID, or NULL if none. 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 f89d340..cbe157b 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 @@ -19,10 +19,10 @@ * Plugin implementation of the 'selection' entity_reference. * * @Plugin( - * id = "base", + * id = "default", * module = "entity_reference", * label = @Translation("Default"), - * group = "base", + * group = "default", * weight = 0, * derivative = "Drupal\entity_reference\Plugin\Derivative\SelectionBase" * ) @@ -273,11 +273,7 @@ public function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') { $query = entity_query($target_type); if (!empty($this->instance['settings']['handler_settings']['target_bundles'])) { - // @todo: Taxonomy term's bundle key is vocabulary_machine_name, but - // entity_query() fails with it, so for now hardcode the vid, until - // http://drupal.org/node/1552396 is fixed. - $bundle_key = $target_type != 'taxonomy_term' ? $entity_info['entity_keys']['bundle'] : 'vid'; - $query->condition($bundle_key, $this->instance['settings']['handler_settings']['target_bundles'], 'IN'); + $query->condition($entity_info['entity_keys']['bundle'], $this->instance['settings']['handler_settings']['target_bundles'], 'IN'); } if (isset($match) && isset($entity_info['entity_keys']['label'])) { diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteTagsWidget.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteTagsWidget.php index c19b8a6..703684d 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteTagsWidget.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteTagsWidget.php @@ -34,13 +34,6 @@ class AutocompleteTagsWidget extends AutocompleteWidgetBase { /** - * Overrides Drupal\entity_reference\Plugin\field\widget\AutocompleteWidgetBase::formElement(). - */ - public function formElement(array $items, $delta, array $element, $langcode, array &$form, array &$form_state) { - return $this->prepareElement($items, $delta, $element, $langcode, $form, $form_state); - } - - /** * Overrides Drupal\entity_reference\Plugin\field\widget\AutocompleteWidgetBase::elementValidate() */ public function elementValidate($element, &$form_state, $form) { diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidget.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidget.php index 2663bdb..ad58bda 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidget.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidget.php @@ -50,8 +50,7 @@ public function formElement(array $items, $delta, array $element, $langcode, arr $items = array(); } - $element = $this->prepareElement($items, $delta, $element, $langcode, $form, $form_state); - return array('target_id' => $element); + return parent::formElement($items, $delta, $element, $langcode, $form, $form_state); } /** diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidgetBase.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidgetBase.php index 5ffd0f9..276b19b 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidgetBase.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidgetBase.php @@ -21,21 +21,19 @@ */ public function settingsForm(array $form, array &$form_state) { $element['match_operator'] = array( - '#type' => 'select', + '#type' => 'radios', '#title' => t('Autocomplete matching'), '#default_value' => $this->getSetting('match_operator'), '#options' => array( 'STARTS_WITH' => t('Starts with'), 'CONTAINS' => t('Contains'), ), - '#description' => t('Select the method used to collect autocomplete suggestions. Note that Contains can cause performance issues on sites with thousands of nodes.'), + '#description' => t('Select the method used to collect autocomplete suggestions. Note that Contains can cause performance issues on sites with thousands of entities.'), ); $element['size'] = array( - '#type' => 'textfield', + '#type' => 'number', '#title' => t('Size of textfield'), '#default_value' => $this->getSetting('size'), - '#element_validate' => array('form_validate_number'), - // Minimum value for form_validate_number(). '#min' => 1, '#required' => TRUE, ); @@ -55,14 +53,6 @@ public function settingsForm(array $form, array &$form_state) { * Implements Drupal\field\Plugin\Type\Widget\WidgetInterface::formElement(). */ public function formElement(array $items, $delta, array $element, $langcode, array &$form, array &$form_state) { - $element = $this->prepareElement($items, $delta, $element, $langcode, $form, $form_state, 'entity_reference/autocomplete/single'); - return array('target_id' => $element); - } - - /** - * Prepares the element. - */ - protected function prepareElement(array $items, $delta, array $element, $langcode, array &$form, array &$form_state) { $instance = $this->instance; $field = $this->field; $entity = isset($element['#entity']) ? $element['#entity'] : NULL; @@ -72,7 +62,7 @@ protected function prepareElement(array $items, $delta, array $element, $langcod $autocomplete_path .= '/' . $field['field_name'] . '/' . $instance['entity_type'] . '/' . $instance['bundle'] . '/'; // Use as a placeholder in the URL when we don't have an entity. - // Most webservers collapse two consecutive slashes. + // Most web servers collapse two consecutive slashes. $id = 'NULL'; if ($entity && $entity_id = $entity->id()) { $id = $entity_id; @@ -88,7 +78,8 @@ protected function prepareElement(array $items, $delta, array $element, $langcod '#placeholder' => $this->getSetting('placeholder'), '#element_validate' => array(array($this, 'elementValidate')), ); - return $element; + + return array('target_id' => $element); } /** diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAdminTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAdminTest.php index 48f6f15..4e68fc4 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAdminTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAdminTest.php @@ -80,7 +80,7 @@ public function testFieldAdminHandler() { $this->drupalPost(NULL, array(), t('Save field settings')); // The base handler should be selected by default. - $this->assertFieldByName('instance[settings][handler]', 'base'); + $this->assertFieldByName('instance[settings][handler]', 'default'); // The base handler settings should be displayed. $entity_type = 'node'; diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php index 7ea85c6..821ac44 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php @@ -27,7 +27,7 @@ public static function getInfo() { function setUp() { parent::setUp(); - // Create a "referecning" and "referenced" node types. + // Create a "referencing" and "referenced" node types. $referencing = $this->drupalCreateContentType(); $this->referencing_type = $referencing->type; @@ -53,7 +53,7 @@ function setUp() { 'entity_type' => 'node', 'bundle' => $referencing->type, 'settings' => array( - 'handler' => 'base', + 'handler' => 'default', 'handler_settings' => array( // Reference a single vocabulary. 'target_bundles' => array( diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutocompleteTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutocompleteTest.php index fb4b4df..968f9bb 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutocompleteTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutocompleteTest.php @@ -48,7 +48,7 @@ function setUp() { 'type' => 'options_select', ), 'settings' => array( - 'handler' => 'base', + 'handler' => 'default', 'handler_settings' => array( 'target_bundles' => array( $this->vocabulary->id(), diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceItemTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceItemTest.php index ab6a6c3..7a0f326 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceItemTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceItemTest.php @@ -56,7 +56,7 @@ public function setUp() { 'type' => 'options_select', ), 'settings' => array( - 'handler' => 'base', + 'handler' => 'default', 'handler_settings' => array(), ), ); diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php index d6c958d..048e1ed 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php @@ -70,7 +70,7 @@ public function testNodeHandler() { ); $instance = array( 'settings' => array( - 'handler' => 'base', + 'handler' => 'default', 'handler_settings' => array( 'target_bundles' => array(), ), @@ -208,7 +208,7 @@ public function testUserHandler() { ); $instance = array( 'settings' => array( - 'handler' => 'base', + 'handler' => 'default', 'handler_settings' => array( 'target_bundles' => array(), ), @@ -348,7 +348,7 @@ public function testCommentHandler() { ); $instance = array( 'settings' => array( - 'handler' => 'base', + 'handler' => 'default', 'handler_settings' => array( 'target_bundles' => array(), ), diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionSortTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionSortTest.php index fa0a39d..dedcbe7 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionSortTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionSortTest.php @@ -68,7 +68,7 @@ public function testSort() { $instance = array( 'settings' => array( - 'handler' => 'base', + 'handler' => 'default', 'handler_settings' => array( 'target_bundles' => array(), // Add sorting. diff --git a/core/modules/field_ui/field_ui.admin.inc b/core/modules/field_ui/field_ui.admin.inc index 5764343..f597491 100644 --- a/core/modules/field_ui/field_ui.admin.inc +++ b/core/modules/field_ui/field_ui.admin.inc @@ -886,7 +886,7 @@ function field_ui_field_edit_form($form, &$form_state, $instance) { ); // Add additional field instance settings from the field module. - $additions = module_invoke($field['module'], 'field_instance_settings_form', $field, $instance); + $additions = module_invoke($field['module'], 'field_instance_settings_form', $field, $instance, $form_state); if (is_array($additions)) { $form['instance']['settings'] = $additions; $form['instance']['settings']['#weight'] = 10; diff --git a/core/modules/field_ui/field_ui.api.php b/core/modules/field_ui/field_ui.api.php index cb55362..eb72e04 100644 --- a/core/modules/field_ui/field_ui.api.php +++ b/core/modules/field_ui/field_ui.api.php @@ -58,11 +58,13 @@ function hook_field_settings_form($field, $instance, $has_data) { * The field structure being configured. * @param $instance * The instance structure being configured. + * @param array $form_state + * The form state of the (entire) configuration form. * * @return * The form definition for the field instance settings. */ -function hook_field_instance_settings_form($field, $instance) { +function hook_field_instance_settings_form($field, $instance, $form_state) { $settings = $instance['settings']; $form['text_processing'] = array( diff --git a/core/modules/file/lib/Drupal/file/Plugin/entity_reference/selection/FileSelection.php b/core/modules/file/lib/Drupal/file/Plugin/entity_reference/selection/FileSelection.php index 1f46441..d4aa678 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/entity_reference/selection/FileSelection.php +++ b/core/modules/file/lib/Drupal/file/Plugin/entity_reference/selection/FileSelection.php @@ -16,11 +16,11 @@ * Provides specific access control for the file entity type. * * @Plugin( - * id = "base_file", - * module = "entity_reference", + * id = "file_default", + * module = "file", * label = @Translation("File selection"), * entity_types = {"file"}, - * group = "base", + * group = "default", * weight = 1 * ) */ diff --git a/core/modules/node/lib/Drupal/node/Plugin/entity_reference/selection/NodeSelection.php b/core/modules/node/lib/Drupal/node/Plugin/entity_reference/selection/NodeSelection.php index c785af9..bb252df 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/entity_reference/selection/NodeSelection.php +++ b/core/modules/node/lib/Drupal/node/Plugin/entity_reference/selection/NodeSelection.php @@ -16,11 +16,11 @@ * Provides specific access control for the node entity type. * * @Plugin( - * id = "base_node", - * module = "entity_reference", + * id = "node_default", + * module = "node", * label = @Translation("Node selection"), * entity_types = {"node"}, - * group = "base", + * group = "default", * weight = 1 * ) */ 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 df87767..cb6bb5f 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 @@ -16,11 +16,11 @@ * Provides specific access control for the taxonomy_term entity type. * * @Plugin( - * id = "base_taxonomy_term", - * module = "entity_reference", + * id = "taxonomy_term_default", + * module = "taxonomy", * label = @Translation("Taxonomy Term selection"), * entity_types = {"taxonomy_term"}, - * group = "base", + * group = "default", * weight = 1 * ) */ diff --git a/core/modules/user/lib/Drupal/user/Plugin/entity_reference/selection/UserSelection.php b/core/modules/user/lib/Drupal/user/Plugin/entity_reference/selection/UserSelection.php index 4a1352b..ae98b08 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/entity_reference/selection/UserSelection.php +++ b/core/modules/user/lib/Drupal/user/Plugin/entity_reference/selection/UserSelection.php @@ -17,11 +17,11 @@ * Provides specific access control for the user entity type. * * @Plugin( - * id = "base_user", - * module = "entity_reference", + * id = "user_default", + * module = "user", * label = @Translation("User selection"), * entity_types = {"user"}, - * group = "base", + * group = "default", * weight = 1 * ) */ 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 a47529e..40e2cbd 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 @@ -12,7 +12,6 @@ use Drupal\Core\Database\Query\SelectInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\entity_reference\Plugin\Type\Selection\SelectionInterface; -use Drupal\views\ViewsException; /** * Plugin implementation of the 'selection' entity_reference. @@ -126,7 +125,7 @@ protected function initializeView($match = NULL, $match_operator = 'CONTAINS', $ // 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)) { - throw new ViewsException('The view %view_name is no longer eligible for the %field_name field.', array('%view_name' => $view_name, '%field_name' => $this->instance['label'])); + throw new \RuntimeException('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); diff --git a/core/modules/views/lib/Drupal/views/ViewsException.php b/core/modules/views/lib/Drupal/views/ViewsException.php deleted file mode 100644 index 8085db2..0000000 --- a/core/modules/views/lib/Drupal/views/ViewsException.php +++ /dev/null @@ -1,15 +0,0 @@ -