You are here

class EntityLegalDocumentVersion in Entity Legal 7.2

Same name and namespace in other branches
  1. 7 entity_legal.entity.inc \EntityLegalDocumentVersion

Legal Document entity version class.

Hierarchy

Expanded class hierarchy of EntityLegalDocumentVersion

1 string reference to 'EntityLegalDocumentVersion'
entity_legal_entity_info in ./entity_legal.module
Implements hook_entity_info().

File

./entity_legal.entity.inc, line 344
Entity API main classes used by entity_legal module.

View source
class EntityLegalDocumentVersion extends Entity {

  /**
   * {@inheritdoc}
   */
  public function __construct(array $values = array(), $entity_type = NULL) {
    Entity::__construct($values, ENTITY_LEGAL_DOCUMENT_VERSION_ENTITY_NAME);
  }

  /**
   * Get the label of the legal document version entity.
   *
   * @param bool $sanitize
   *   Whether or not to sanitize the label, defaults to TRUE.
   *
   * @return string
   *   The label string.
   */
  public function label($sanitize = FALSE) {
    $label_text = isset($this->label) ? $this->label : '';
    if ($sanitize) {
      $label_text = check_plain($label_text);
    }
    return $label_text;
  }

  /**
   * Get the date for a given entity property.
   *
   * @param string $type
   *   The type of date to retrieve, updated or created.
   *
   * @return string
   *   The formatted date.
   */
  public function getFormattedDate($type = 'updated') {
    switch ($type) {
      case 'updated':
        return format_date($this->updated);
      case 'created':
        return format_date($this->created);
    }
  }

  /**
   * Get the acceptances for this entity legal document version.
   *
   * @param bool|object $account
   *   The Drupal user account to check for, or get all acceptances if FALSE.
   *
   * @return array
   *   The acceptance entities keyed by acceptance id.
   */
  public function getAcceptances($account = FALSE) {
    return entity_get_controller($this->entityType)
      ->getAcceptances($this, $account);
  }

  /**
   * Get attached document entity.
   *
   * @return EntityLegalDocument
   *   The attached document entity.
   */
  public function getDocument() {
    return entity_load_single(ENTITY_LEGAL_DOCUMENT_ENTITY_NAME, $this->document_name);
  }

  /**
   * Override buildContent() to add the acceptance form.
   */
  public function buildContent($view_mode = 'full', $langcode = NULL) {
    $content = parent::buildContent($view_mode, $langcode);

    // Get acceptance form or information for the current user.
    $document = $this
      ->getDocument();
    if ($document
      ->userMustAgree() && user_is_logged_in() && !$document
      ->userHasAgreed()) {
      $content['acceptance'] = $document
        ->getAcceptanceForm();
    }

    // Move acceptance to the bottom of the agreement.
    $content['acceptance']['#weight'] = 99;
    return $content;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Entity::$defaultLabel protected property 1
Entity::$entityInfo protected property
Entity::$entityType protected property
Entity::$idKey protected property
Entity::$wrapper protected property
Entity::bundle public function Returns the bundle of the entity. Overrides EntityInterface::bundle
Entity::defaultLabel protected function Defines the entity label if the 'entity_class_label' callback is used. 1
Entity::defaultUri protected function Override this in order to implement a custom default URI and specify 'entity_class_uri' as 'uri callback' hook_entity_info().
Entity::delete public function Permanently deletes the entity. Overrides EntityInterface::delete
Entity::entityInfo public function Returns the info of the type of the entity. Overrides EntityInterface::entityInfo
Entity::entityType public function Returns the type of the entity. Overrides EntityInterface::entityType
Entity::export public function Exports the entity. Overrides EntityInterface::export
Entity::getTranslation public function Gets the raw, translated value of a property or field. Overrides EntityInterface::getTranslation
Entity::hasStatus public function Checks if the entity has a certain exportable status. Overrides EntityInterface::hasStatus
Entity::identifier public function Returns the entity identifier, i.e. the entities name or numeric id. Overrides EntityInterface::identifier
Entity::internalIdentifier public function Returns the internal, numeric identifier. Overrides EntityInterface::internalIdentifier
Entity::isDefaultRevision public function Checks whether the entity is the default revision. Overrides EntityInterface::isDefaultRevision
Entity::save public function Permanently saves the entity. Overrides EntityInterface::save
Entity::setUp protected function Set up the object instance on construction or unserializiation.
Entity::uri public function Returns the uri of the entity just as entity_uri(). Overrides EntityInterface::uri
Entity::view public function Generate an array for rendering the entity. Overrides EntityInterface::view
Entity::wrapper public function Returns the EntityMetadataWrapper of the entity. Overrides EntityInterface::wrapper
Entity::__sleep public function Magic method to only serialize what's necessary.
Entity::__wakeup public function Magic method to invoke setUp() on unserialization.
EntityLegalDocumentVersion::buildContent public function Override buildContent() to add the acceptance form. Overrides Entity::buildContent
EntityLegalDocumentVersion::getAcceptances public function Get the acceptances for this entity legal document version.
EntityLegalDocumentVersion::getDocument public function Get attached document entity.
EntityLegalDocumentVersion::getFormattedDate public function Get the date for a given entity property.
EntityLegalDocumentVersion::label public function Get the label of the legal document version entity. Overrides Entity::label
EntityLegalDocumentVersion::__construct public function Overrides Entity::__construct