You are here

abstract class EntityShareEntityAbstract in Entity Share 7

Entity Share Entity class.

Hierarchy

Expanded class hierarchy of EntityShareEntityAbstract

File

includes/entity_share.entity.abstract.inc, line 11
Class for handling Entity Export Abstract.

View source
abstract class EntityShareEntityAbstract {

  /**
   * Original entity.
   *
   * @var object
   *   Original entity.
   */
  protected $originalEntity;

  /**
   * Entity.
   *
   * @var object
   *   Working entity.
   */
  protected $entity;

  /**
   * Internal Drupal fields list.
   *
   * @var array
   *   Internal Drupal fields list for exclusion.
   */
  protected $internalFields = array(
    'vid',
    'uid',
    'title',
    'log',
    'status',
    'comment',
    'promote',
    'sticky',
    'vuuid',
    'nid',
    'type',
    'language',
    'created',
    'changed',
    'tnid',
    'translate',
    'uuid',
    'revision_timestamp',
    'revision_uid',
    'metatags',
    'rdf_mapping',
    'entity_type',
    'translations',
    'name',
    'picture',
    'data',
    'print_html_display',
    'print_html_display_comment',
    'print_html_display_urllist',
    'print_pdf_display',
    'print_pdf_display_comment',
    'print_pdf_display_urllist',
    'print_pdf_size',
    'print_pdf_orientation',
    'item_id',
    'revision_id',
    'default_revision',
    'archived',
  );

  /**
   * Value sub dimensions.
   *
   * @var array
   *   Value sub dimensions to treat for embedded medias in RTE.
   */
  protected $rteKeys = array(
    'value',
    'safe_value',
    'summary',
    'safe_summary',
  );

  /**
   * Constructor. Initialize properties.
   *
   * @param object $entity
   *   Entity to share.
   */
  public function __construct($entity) {
    if (empty($entity)) {
      throw new EntityShareException('Entity can\\t be empty.');
    }
    $this->originalEntity = $entity;
    $this->entity = $entity;
  }

  /**
   * Get the original unmodified entity.
   *
   * @return object
   *   Original entity to share.
   */
  public function getOriginalEntity() {
    return $this->originalEntity;
  }

  /**
   * Get the modified entity.
   *
   * @return object
   *   Entity to share.
   */
  public function getEntity() {
    return $this->entity;
  }

  /**
   * Get the current entity type.
   *
   * @return mixed
   *   Type of the Entity.
   */
  public function getEntityType() {
    return isset($this->entity->entity_type) ? $this->entity->entity_type : FALSE;
  }

  /**
   * Walk though the entity to do special treatment in function of field type.
   *
   * @param object $entity
   *   Entity or sub entity to share.
   */
  public function contentFieldWalk($entity = NULL) {
    if (!isset($entity)) {
      $entity = $this
        ->getEntity();
    }

    // Fix some exceptions or warnings linked to the json conversion.
    if (isset($entity->translations) && !is_object($entity->translations)) {
      $entity->translations = (object) $entity->translations;
    }

    // Load additional needed information.
    foreach ($entity as $field_name => $field_value) {
      if (in_array($field_name, $this->internalFields)) {
        continue;
      }

      // Needed to detect that a field is a collection field.
      $field_info = field_info_field($field_name);
      if (!isset($field_info['type'])) {
        continue;
      }
      $this
        ->manageField($field_info, $field_name, $entity);
    }
  }

  /**
   * Manage the field.
   *
   * @param array $field_info
   *   Informations of the current field.
   * @param string $field_name
   *   Name of the current field.
   * @param object $entity
   *   Entity or sub entity to share.
   */
  protected abstract function manageField(array $field_info, $field_name, $entity = NULL);

  /**
   * Execute the treatment.
   *
   * @return mixed
   *   Exported or imported entity.
   */
  public abstract function execute();

}

Members

Namesort descending Modifiers Type Description Overrides
EntityShareEntityAbstract::$entity protected property Entity.
EntityShareEntityAbstract::$internalFields protected property Internal Drupal fields list.
EntityShareEntityAbstract::$originalEntity protected property Original entity.
EntityShareEntityAbstract::$rteKeys protected property Value sub dimensions.
EntityShareEntityAbstract::contentFieldWalk public function Walk though the entity to do special treatment in function of field type. 1
EntityShareEntityAbstract::execute abstract public function Execute the treatment. 2
EntityShareEntityAbstract::getEntity public function Get the modified entity.
EntityShareEntityAbstract::getEntityType public function Get the current entity type.
EntityShareEntityAbstract::getOriginalEntity public function Get the original unmodified entity.
EntityShareEntityAbstract::manageField abstract protected function Manage the field. 2
EntityShareEntityAbstract::__construct public function Constructor. Initialize properties. 1