You are here

abstract class AbstractFieldSynonymsBehavior in Synonyms 7

Abstract class for providing synonyms from fields attached to entities.

Hierarchy

Expanded class hierarchy of AbstractFieldSynonymsBehavior

File

synonyms_provider_field/includes/AbstractFieldSynonymsBehavior.class.inc, line 11
Definition of AbstractFieldSynonymsBehavior class.

View source
abstract class AbstractFieldSynonymsBehavior extends AbstractSynonymsBehavior {

  /**
   * Field definition array on which this provider was initialized.
   *
   * @var array
   */
  protected $field;

  /**
   * Field instance definition on which this provider was initialized.
   *
   * @var array
   */
  protected $instance;
  public function __construct($behavior_implementation) {
    parent::__construct($behavior_implementation);
    $this->field = field_info_field(synonyms_provider_field_field_name($behavior_implementation['provider']));
    $this->instance = field_info_instance($behavior_implementation['entity_type'], $this->field['field_name'], $behavior_implementation['bundle']);
  }
  public function featuresExportPipe() {
    $pipe = parent::featuresExportPipe();

    // We include the Features component for the underlying field on which this
    // synonyms provider is built.
    $pipe['field'][] = implode('-', array(
      $this->behavior_implementation['entity_type'],
      $this->behavior_implementation['bundle'],
      $this->field['field_name'],
    ));
    return $pipe;
  }

  /**
   * Retrieve items of the underlying field in this behavior implementation.
   *
   * @param object $entity
   *   Entity whose items should be retrieved
   * @param string $langcode
   *   Language code for which to retrieve items from the entity, if one is
   *   known
   *
   * @return array
   *   Array of items that provided entity has in the field on which behavior
   *   implementation is set up
   */
  protected function entityItems($entity, $langcode = NULL) {
    $items = field_get_items($this->instance['entity_type'], $entity, $this->field['field_name'], $langcode);
    return is_array($items) ? $items : array();
  }

  /**
   * Filter $items only to contain unique values.
   *
   * @param array $items
   *   Array of field items that should be filtered to contain only unique
   *   values
   * @param array $unique_index
   *   Array of column names that define uniqueness for an item
   *
   * @return array
   *   Only unique items from the provided $items array
   */
  protected function uniqueItems($items, $unique_index) {
    $index = array();
    foreach ($items as $item) {
      $item_index = array();
      foreach ($unique_index as $column) {
        $item_index[] = is_scalar($column) ? $column : serialize($column);
      }
      $index[serialize($item_index)] = $item;
    }
    return array_values($index);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AbstractFieldSynonymsBehavior::$field protected property Field definition array on which this provider was initialized.
AbstractFieldSynonymsBehavior::$instance protected property Field instance definition on which this provider was initialized.
AbstractFieldSynonymsBehavior::entityItems protected function Retrieve items of the underlying field in this behavior implementation.
AbstractFieldSynonymsBehavior::featuresExportPipe public function Collect info on features pipe during invocation of hook_features_export(). Overrides AbstractSynonymsBehavior::featuresExportPipe
AbstractFieldSynonymsBehavior::uniqueItems protected function Filter $items only to contain unique values.
AbstractFieldSynonymsBehavior::__construct public function Overrides AbstractSynonymsBehavior::__construct
AbstractSynonymsBehavior::$behavior_implementation protected property Behavior implementation on which this class was initialized.
AbstractSynonymsBehavior::COLUMN_ENTITY_ID_PLACEHOLDER constant Constant which denotes placeholder of an entity ID column.
AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER constant Constant which denotes placeholder of a synonym column.
AbstractSynonymsBehavior::synonymsFindProcessCondition protected function Process condition in 'synonymsFind' method.
SynonymsBehavior::extractSynonyms public function Extract synonyms from an entity within a specific behavior implementation. 7
SynonymsBehavior::mergeEntityAsSynonym public function Add an entity as a synonym into another entity. 7
SynonymsBehavior::synonymsFind public function Look up entities by their synonyms within a behavior implementation. 7