You are here

class CerFieldChain in Corresponding Entity References 7.3

@file Contains the CerFieldChain class.

Hierarchy

Expanded class hierarchy of CerFieldChain

File

includes/CerFieldChain.inc, line 8
Contains the CerFieldChain class.

View source
class CerFieldChain extends FieldChain {

  /**
   * Convenience method. Returns a handler for this chain in the context of
   * the given entity.
   *
   * @return CerFieldChainHandler
   */
  public function getHandler(EntityDrupalWrapper $entity) {
    return new CerFieldChainHandler($this, $entity);
  }

  /**
   * Gets a regular expression to match field chain identifiers that this chain
   * can reference, e.g. /^node:(page|article):/
   */
  public function regex() {
    $end = $this
      ->end();
    return '/^' . $end
      ->getTargetType() . ':(' . implode('|', $end
      ->getTargetBundles()) . '):/';
  }

  /**
   * Returns a Features export pipe for this chain, including every field and
   * field instance in it.
   */
  public function export() {
    $pipe = array();
    foreach ($this->chain as $field) {
      $pipe['field_instance'][] = "{$field->entityType}-{$field->bundle}-{$field->name}";
    }
    return $pipe;
  }

  /**
   * Returns an array of every possible field chain for every field defined in
   * hook_cer_fields().
   *
   * @return array
   */
  public static function collectAll() {
    $chains = array();
    foreach (array_keys(CerField::getPluginInfo()) as $identifier) {
      $chains = array_merge($chains, self::collect($identifier));
    }
    return $chains;
  }

  /**
   * Returns an array of every possible field chain for a single field,
   * identified by its key in hook_cer_fields().
   *
   * @return array
   */
  public static function collect($identifier) {
    $chains = array();
    $chain = new CerFieldChain();
    $chain
      ->addField(CerField::getPlugin($identifier), $chains);
    return $chains;
  }

  /**
   * Constructs and returns a CerFieldChain object from an encoded string
   * of field plugin identifiers glued together with ::.
   *
   * @return CerFieldChain
   */
  public static function unpack($identifier) {
    $chain = new CerFieldChain();
    foreach (array_reverse(explode('::', $identifier)) as $field) {
      $chain
        ->addField(CerField::getPlugin($field));
    }
    return $chain;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CerFieldChain::collect public static function Returns an array of every possible field chain for a single field, identified by its key in hook_cer_fields().
CerFieldChain::collectAll public static function Returns an array of every possible field chain for every field defined in hook_cer_fields().
CerFieldChain::export public function Returns a Features export pipe for this chain, including every field and field instance in it.
CerFieldChain::getHandler public function Convenience method. Returns a handler for this chain in the context of the given entity.
CerFieldChain::regex public function Gets a regular expression to match field chain identifiers that this chain can reference, e.g. /^node:(page|article):/
CerFieldChain::unpack public static function Constructs and returns a CerFieldChain object from an encoded string of field plugin identifiers glued together with ::.
FieldChain::$chain protected property
FieldChain::$index protected property
FieldChain::addField public function Prepends a field instance to this chain. If $completed is passed, we'll try to find the parents of the instance and recurse upwards, building a tree of "routes" to the instance.
FieldChain::current public function Implements Iterator::current().
FieldChain::end public function Returns the last field in the chain.
FieldChain::key public function Implements Iterator::key().
FieldChain::next public function Implements Iterator::next().
FieldChain::rewind public function Implements Iterator::rewind().
FieldChain::seek public function Implements SeekableIterator::seek().
FieldChain::valid public function Implements Iterator::valid().
FieldChain::__toString public function Represents this chain as a machine-readable string, separating the fields with a T_PAAMAYIM_NEKUDOTAYIM (or, as we call it on planet Earth, a double colon).
FieldChain::__wakeup public function Magic post-unserialization callback. Provides every field in the chain with a reference to its parent (if any) and child (if any), effectively turning the chain into a doubly linked list.