You are here

trait HostingFieldable in Aegir Objects 7.3

@file The HostingFieldable trait.

Hierarchy

File

traits/HostingFieldable.inc, line 6
The HostingFieldable trait.

View source
trait HostingFieldable {

  /**
   * Return the target of an entityreference field.
   */
  public function getEntityReference($field) {
    return $this
      ->getFieldValueType($field, 'target_id');
  }
  public function getFieldValueType($field, $type) {
    if (isset($this->node->{$field}) && $this->node->{$field}) {
      if (isset($this->node->{$field}[$this->node->language])) {
        return $this->node->{$field}[$this->node->language][0][$type];
      }
      else {
        return $this->node->{$field}[0][$type];
      }
    }
  }

  /**
   * Return the target of an entityreference field.
   */
  public function setEntityReference($field, $value) {
    return $this->node->{$field}[$this->node->language][0] = array(
      'target_id' => $value,
      'target_type' => 'node',
    );
  }

  /**
   * Return the value of a field.
   */
  public function getFieldValue($field) {
    return $this
      ->getFieldValueType($field, 'value');
  }

  /**
   * Set the value of a field.
   */
  public function setFieldValue($field, $value) {
    return $this->node->{$field}[$this->node->language][0]['value'] = $value;
  }

  /**
   * Set the value of a property.
   */
  public function setProperty($property, $value) {
    return $this->node->{$property} = $value;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
HostingFieldable::getEntityReference public function Return the target of an entityreference field.
HostingFieldable::getFieldValue public function Return the value of a field.
HostingFieldable::getFieldValueType public function
HostingFieldable::setEntityReference public function Return the target of an entityreference field.
HostingFieldable::setFieldValue public function Set the value of a field.
HostingFieldable::setProperty public function Set the value of a property.