diff --git a/plugins/selection/EntityReference_SelectionHandler_Generic.class.php b/plugins/selection/EntityReference_SelectionHandler_Generic.class.php index fa1e0e3..a607100 100644 --- a/plugins/selection/EntityReference_SelectionHandler_Generic.class.php +++ b/plugins/selection/EntityReference_SelectionHandler_Generic.class.php @@ -152,7 +152,7 @@ class EntityReference_SelectionHandler_Generic implements EntityReference_Select $form['allow_self_reference'] = array( '#type' => 'checkbox', - '#title' => t('Allow to choose self reference.'), + '#title' => t('Allow to choose self reference'), '#description' => t('If checked you will be able to set reference to self entity. Disabled by default'), '#default_value' => $field['settings']['handler_settings']['allow_self_reference'], ); @@ -216,31 +216,31 @@ class EntityReference_SelectionHandler_Generic implements EntityReference_Select * Implements EntityReferenceHandler::validateAutocompleteInput(). */ public function validateAutocompleteInput($input, &$element, &$form_state, $form) { - $entities = $this->getReferencableEntities($input, '=', 6); - if (empty($entities)) { - // Error if there are no entities available for a required field. - form_error($element, t('There are no entities matching "%value"', array('%value' => $input))); - } - elseif (count($entities) > 5) { - // Error if there are more than 5 matching entities. - form_error($element, t('Many entities are called %value. Specify the one you want by appending the id in parentheses, like "@value (@id)"', array( - '%value' => $input, - '@value' => $input, - '@id' => key($entities), - ))); - } - elseif (count($entities) > 1) { - // More helpful error if there are only a few matching entities. - $multiples = array(); - foreach ($entities as $id => $name) { - $multiples[] = $name . ' (' . $id . ')'; - } - form_error($element, t('Multiple entities match this reference; "%multiple"', array('%multiple' => implode('", "', $multiples)))); - } - else { - // Take the one and only matching entity. - return key($entities); + $entities = $this->getReferencableEntities($input, '=', 6); + if (empty($entities)) { + // Error if there are no entities available for a required field. + form_error($element, t('There are no entities matching "%value"', array('%value' => $input))); + } + elseif (count($entities) > 5) { + // Error if there are more than 5 matching entities. + form_error($element, t('Many entities are called %value. Specify the one you want by appending the id in parentheses, like "@value (@id)"', array( + '%value' => $input, + '@value' => $input, + '@id' => key($entities), + ))); + } + elseif (count($entities) > 1) { + // More helpful error if there are only a few matching entities. + $multiples = array(); + foreach ($entities as $id => $name) { + $multiples[] = $name . ' (' . $id . ')'; } + form_error($element, t('Multiple entities match this reference; "%multiple"', array('%multiple' => implode('", "', $multiples)))); + } + else { + // Take the one and only matching entity. + return key($entities); + } } /** @@ -277,7 +277,7 @@ class EntityReference_SelectionHandler_Generic implements EntityReference_Select } } - // Exclude self reference + // Exclude self reference. if (empty($this->field['settings']['handler_settings']['allow_self_reference']) && isset($this->entity)) { list($entity_id,,) = entity_extract_ids($this->entity_type, $this->entity); $query->entityCondition('entity_id', $entity_id, '<>'); diff --git a/plugins/selection/EntityReference_SelectionHandler_Views.class.php b/plugins/selection/EntityReference_SelectionHandler_Views.class.php index 8abf17b..b9f5f0e 100644 --- a/plugins/selection/EntityReference_SelectionHandler_Views.class.php +++ b/plugins/selection/EntityReference_SelectionHandler_Views.class.php @@ -73,7 +73,7 @@ class EntityReference_SelectionHandler_Views implements EntityReference_Selectio $form['allow_self_reference'] = array( '#type' => 'checkbox', - '#title' => t('Allow to choose self reference.'), + '#title' => t('Allow to choose self reference'), '#description' => t('If checked you will be able to set reference to self entity. Disabled by default'), '#default_value' => empty($field['settings']['handler_settings']['allow_self_reference']) ? 0 : 1, ); @@ -86,9 +86,9 @@ class EntityReference_SelectionHandler_Views implements EntityReference_Selectio $display_name = $this->field['settings']['handler_settings']['view']['display_name']; $args = $this->field['settings']['handler_settings']['view']['args']; $entity_type = $this->field['settings']['target_type']; - $allow_self_reference = $this->field['settings']['handler_settings']['allow_self_reference']; $entity_id_to_exclude = FALSE; - if (!$allow_self_reference && isset($this->entity)) { + + if (isset($this->entity) && $this->field['settings']['handler_settings']['allow_self_reference']) { list($entity_id_to_exclude,,) = entity_extract_ids($this->entity_type, $this->entity); } diff --git a/tests/entityreference.handlers.test b/tests/entityreference.handlers.test index 2b8ffd6..0d47d33 100644 --- a/tests/entityreference.handlers.test +++ b/tests/entityreference.handlers.test @@ -683,17 +683,17 @@ class EntityReferenceHandlersTestCase extends DrupalWebTestCase { // Titles contain HTML-special characters to test escaping. $nodes = array( 'node_1' => (object) array( - 'type' => 'article', - 'status' => 1, - 'title' => 'First node', - 'uid' => 1, - ), + 'type' => 'article', + 'status' => 1, + 'title' => 'First node', + 'uid' => 1, + ), 'node_2' => (object) array( - 'type' => 'article', - 'status' => 1, - 'title' => 'Second node', - 'uid' => 1, - ), + 'type' => 'article', + 'status' => 1, + 'title' => 'Second node', + 'uid' => 1, + ), ); $node_labels = array();