You are here

class OgMembership in Organic groups 8

The membership entity that connects a group and a user.

When dealing with non-user entities that are group content, that is content that is associated with a group, we do it via an entity reference field that has the default storage. The only information that we hold is that a group content is referencing a group.

However, when dealing with the user entity we recognize that we need to special case it. It won't suffice to just hold the reference between the user and the group content as it will be laking crucial information such as: the state of the user's membership in the group (active, pending or blocked), the time the membership was created, the user's OG role in the group, etc.

For this meta data we have the fieldable OgMembership entity, that is always connecting between a user and a group. There cannot be an OgMembership entity connecting two non-user entities.

Creating such a relation is done for example in the following way:

$membership = Og::createMembership($entity, $user);
$membership
  ->save();

Notice how the relation of the user to the group also includes the OG audience field name this association was done by. Like this we are able to express different membership types such as the default membership that comes out of the box, or a "premium membership" that can be for example expired after a certain amount of time (the logic for the expired membership in the example is out of the scope of OG core).

Having this field separation is what allows having multiple OG audience fields attached to the user, where each group they are associated with may be a result of different membership types.

Plugin annotation


@ContentEntityType(
  id = "og_membership",
  label = @Translation("OG membership"),
  bundle_label = @Translation("OG membership type"),
  module = "og",
  base_table = "og_membership",
  fieldable = TRUE,
  bundle_entity_type = "og_membership_type",
  entity_keys = {
    "uuid" = "uuid",
    "id" = "id",
    "bundle" = "type",
  },
  bundle_keys = {
    "bundle" = "type",
  },
  handlers = {
    "views_data" = "Drupal\og\OgMembershipViewsData",
    "form" = {
      "subscribe" = "Drupal\og\Form\GroupSubscribeForm",
      "unsubscribe" = "Drupal\og\Form\GroupUnsubscribeConfirmForm",
    },
  }
)

Hierarchy

Expanded class hierarchy of OgMembership

12 files declare their use of OgMembership
AccessByOgMembershipTest.php in tests/src/Kernel/Access/AccessByOgMembershipTest.php
AddSingleOgMembershipRole.php in src/Plugin/Action/AddSingleOgMembershipRole.php
ChangeOgMembershipStateBase.php in src/Plugin/Action/ChangeOgMembershipStateBase.php
DeleteOgMembership.php in src/Plugin/Action/DeleteOgMembership.php
GroupSubscribeFormTest.php in tests/src/Kernel/Form/GroupSubscribeFormTest.php

... See full list

File

src/Entity/OgMembership.php, line 83

Namespace

Drupal\og\Entity
View source
class OgMembership extends ContentEntityBase implements OgMembershipInterface {

  /**
   * {@inheritdoc}
   */
  public function getCreatedTime() : int {
    return $this
      ->getFieldValue('created', 'value') ?: 0;
  }

  /**
   * {@inheritdoc}
   */
  public function setCreatedTime(int $timestamp) : OgMembershipInterface {
    $this
      ->set('created', $timestamp);
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getOwner() {
    assert(!empty($this
      ->get('uid')->entity), new \LogicException(__METHOD__ . '() should only be called on loaded memberships, or on newly created memberships that already have the owner set.'));
    return $this
      ->get('uid')->entity;
  }

  /**
   * {@inheritdoc}
   */
  public function getOwnerId() {
    $owner_id = $this
      ->getFieldValue('uid', 'target_id');
    assert(!empty($owner_id), new \LogicException(__METHOD__ . '() should only be called on loaded memberships, or on newly created memberships that already have the owner set.'));
    return $owner_id;
  }

  /**
   * {@inheritdoc}
   */
  public function setOwner(UserInterface $account) {
    $this
      ->set('uid', $account
      ->id());
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function setOwnerId($uid) {
    $this
      ->set('uid', $uid);
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function setGroup(ContentEntityInterface $group) : OgMembershipInterface {
    $this
      ->set('entity_type', $group
      ->getEntityTypeId());
    $this
      ->set('entity_bundle', $group
      ->bundle());
    $this
      ->set('entity_id', $group
      ->id());
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getGroupEntityType() : string {
    $entity_type = $this
      ->getFieldValue('entity_type', 'value') ?: '';
    assert(!empty($entity_type), new \LogicException(__METHOD__ . '() should only be called on loaded memberships, or on newly created memberships that already have the group type set.'));
    return $entity_type;
  }

  /**
   * {@inheritdoc}
   */
  public function getGroupBundle() : string {
    $bundle = $this
      ->getFieldValue('entity_bundle', 'value') ?: '';
    assert(!empty($bundle), new \LogicException(__METHOD__ . '() should only be called on loaded memberships, or on newly created memberships that already have the group bundle set.'));
    return $bundle;
  }

  /**
   * {@inheritdoc}
   */
  public function getGroupId() : string {
    $entity_id = $this
      ->getFieldValue('entity_id', 'value') ?: '';
    assert(!empty($entity_id), new \LogicException(__METHOD__ . '() should only be called on loaded memberships, or on newly created memberships that already have the group ID set.'));
    return $entity_id;
  }

  /**
   * Checks if a group has already been populated on the membership.
   *
   * The group is required for a membership, so it is always present if a
   * membership has been saved. This is intended for internal use to verify if
   * a group is present when methods are called on a membership that is possibly
   * still under construction.
   *
   * For performance reasons this avoids loading the full group entity just for
   * this purpose, and relies only on the fact that the data for the entity is
   * populated in the relevant fields. This should give us the same indication,
   * but with a lower performance cost, especially for users that are a member
   * of a large number of groups.
   *
   * @return bool
   *   Whether or not the group is already present.
   */
  protected function hasGroup() : bool {
    $has_group = !empty($this
      ->getFieldValue('entity_type', 'value')) && !empty($this
      ->getFieldValue('entity_bundle', 'value')) && !empty($this
      ->getFieldValue('entity_id', 'value'));
    return $has_group;
  }

  /**
   * {@inheritdoc}
   */
  public function getGroup() : ?ContentEntityInterface {
    $entity_type = $this
      ->getGroupEntityType();
    $entity_id = $this
      ->getGroupId();
    return \Drupal::entityTypeManager()
      ->getStorage($entity_type)
      ->load($entity_id);
  }

  /**
   * {@inheritdoc}
   */
  public function setState(string $state) : OgMembershipInterface {
    $this
      ->set('state', $state);
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getState() : string {
    return $this
      ->getFieldValue('state', 'value') ?: '';
  }

  /**
   * {@inheritdoc}
   */
  public function getType() : string {
    return $this
      ->bundle();
  }

  /**
   * {@inheritdoc}
   */
  public function addRole(OgRoleInterface $role) : OgMembershipInterface {
    $roles = $this
      ->getRoles();
    $roles[] = $role;
    return $this
      ->setRoles($roles);
  }

  /**
   * {@inheritdoc}
   */
  public function revokeRole(OgRoleInterface $role) : OgMembershipInterface {
    return $this
      ->revokeRoleById($role
      ->id());
  }

  /**
   * {@inheritdoc}
   */
  public function revokeRoleById(string $role_id) : OgMembershipInterface {
    $roles = $this
      ->getRoles();
    foreach ($roles as $key => $existing_role) {
      if ($existing_role
        ->id() == $role_id) {
        unset($roles[$key]);

        // We can stop iterating.
        break;
      }
    }
    return $this
      ->setRoles($roles);
  }

  /**
   * {@inheritdoc}
   */
  public function getRoles() : array {
    $roles = [];

    // Add the member role. This is only possible if a group has been set on the
    // membership.
    if ($this
      ->hasGroup()) {
      $roles = [
        OgRole::getRole($this
          ->getGroupEntityType(), $this
          ->getGroupBundle(), OgRoleInterface::AUTHENTICATED),
      ];
    }
    $roles = array_merge($roles, $this
      ->get('roles')
      ->referencedEntities());
    return $roles;
  }

  /**
   * {@inheritdoc}
   */
  public function setRoles(array $roles = []) : OgMembershipInterface {
    $roles = array_filter($roles, function (OgRole $role) {
      return !($role
        ->getName() == OgRoleInterface::AUTHENTICATED);
    });
    $role_ids = array_map(function (OgRole $role) {
      return $role
        ->id();
    }, $roles);
    $this
      ->set('roles', array_unique($role_ids));
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getRolesIds() : array {

    // Only use $this->get() if it is already populated. If it is not available
    // then use the raw value. This field is not translatable so we do not need
    // the slow field definition lookup from $this->getTranslatedField().
    if (isset($this->fields['roles'][LanguageInterface::LANGCODE_DEFAULT])) {
      $values = $this
        ->get('roles')
        ->getValue();
    }
    else {
      $values = $this->values['roles'][LanguageInterface::LANGCODE_DEFAULT] ?? [];
    }
    $roles_ids = array_column($values, 'target_id');

    // Add the member role. This is only possible if a group has been set on the
    // membership.
    if ($this
      ->hasGroup()) {
      $roles_ids[] = "{$this->getGroupEntityType()}-{$this->getGroupBundle()}-" . OgRoleInterface::AUTHENTICATED;
    }
    return $roles_ids;
  }

  /**
   * {@inheritdoc}
   */
  public function isRoleValid(OgRoleInterface $role) : bool {
    $group = $this
      ->getGroup();

    // If there is no group yet then we cannot determine whether the role is
    // valid.
    if (!$group) {
      throw new \LogicException('Cannot determine whether a role is valid for a membership that doesn\'t have a group.');
    }

    // Non-member roles are never valid for any membership.
    if ($role
      ->getName() == OgRoleInterface::ANONYMOUS) {
      return FALSE;
    }
    elseif ($role
      ->getGroupType() !== $group
      ->getEntityTypeId() || $role
      ->getGroupBundle() !== $group
      ->bundle()) {
      return FALSE;
    }
    return TRUE;
  }

  /**
   * {@inheritdoc}
   */
  public function hasRole(string $role_id) : bool {
    return in_array($role_id, $this
      ->getRolesIds());
  }

  /**
   * {@inheritdoc}
   */
  public function hasPermission(string $permission) : bool {

    // Blocked users do not have any permissions.
    if ($this
      ->isBlocked()) {
      return FALSE;
    }
    return (bool) array_filter($this
      ->getRoles(), function (OgRole $role) use ($permission) {
      return $role
        ->hasPermission($permission);
    });
  }

  /**
   * {@inheritdoc}
   */
  public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
    $fields = [];
    $fields['id'] = BaseFieldDefinition::create('integer')
      ->setLabel(new TranslatableMarkup('ID'))
      ->setDescription(t("The group membership's unique ID."))
      ->setReadOnly(TRUE)
      ->setSetting('unsigned', TRUE);
    $fields['uuid'] = BaseFieldDefinition::create('uuid')
      ->setLabel(new TranslatableMarkup('UUID'))
      ->setDescription(new TranslatableMarkup('The membership UUID.'))
      ->setReadOnly(TRUE);
    $fields['type'] = BaseFieldDefinition::create('entity_reference')
      ->setLabel(new TranslatableMarkup('Type'))
      ->setDescription(new TranslatableMarkup('The bundle of the membership'))
      ->setSetting('target_type', 'og_membership_type');
    $fields['uid'] = BaseFieldDefinition::create('entity_reference')
      ->setLabel(new TranslatableMarkup('Member User ID'))
      ->setDescription(new TranslatableMarkup('The user ID of the member.'))
      ->setSetting('target_type', 'user');
    $fields['entity_type'] = BaseFieldDefinition::create('string')
      ->setLabel(new TranslatableMarkup('Group entity type'))
      ->setDescription(new TranslatableMarkup('The entity type of the group.'));
    $fields['entity_bundle'] = BaseFieldDefinition::create('string')
      ->setLabel(new TranslatableMarkup('Group bundle ID'))
      ->setDescription(new TranslatableMarkup('The bundle ID of the group.'));
    $fields['entity_id'] = BaseFieldDefinition::create('string')
      ->setLabel(new TranslatableMarkup('Group entity ID'))
      ->setDescription(new TranslatableMarkup('The entity ID of the group.'));
    $fields['state'] = BaseFieldDefinition::create('string')
      ->setLabel(new TranslatableMarkup('State'))
      ->setDescription(new TranslatableMarkup('The user membership state: active, pending, or blocked.'))
      ->setDefaultValue(OgMembershipInterface::STATE_ACTIVE);
    $fields['roles'] = BaseFieldDefinition::create('entity_reference')
      ->setLabel(new TranslatableMarkup('Roles'))
      ->setDescription(new TranslatableMarkup('The OG roles related to an OG membership entity.'))
      ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
      ->setDisplayOptions('view', [
      'label' => 'hidden',
      'type' => 'entity_reference_label',
      'weight' => 0,
    ])
      ->setSetting('target_type', 'og_role');
    $fields['created'] = BaseFieldDefinition::create('created')
      ->setLabel(new TranslatableMarkup('Create'))
      ->setDescription(new TranslatableMarkup('The Unix timestamp when the membership was created.'));
    $fields['language'] = BaseFieldDefinition::create('language')
      ->setLabel(new TranslatableMarkup('Language'))
      ->setDescription(new TranslatableMarkup('The {languages}.language of this membership.'));
    return $fields;
  }

  /**
   * {@inheritdoc}
   */
  public function preSave(EntityStorageInterface $storage) {

    // Check the value directly rather than using the entity, if there is one.
    // This will watch actual empty values and '0'.
    if (!($uid = $this
      ->get('uid')->target_id)) {

      // Throw a generic logic exception as this will likely get caught in
      // \Drupal\Core\Entity\Sql\SqlContentEntityStorage::save and turned into
      // an EntityStorageException anyway.
      throw new \LogicException('OG membership can not be created for an empty or anonymous user.');
    }
    if (!($entity_id = $this
      ->get('entity_id')->value)) {

      // Group was not set.
      throw new \LogicException('Membership cannot be set for an empty or an unsaved group.');
    }
    if (!($group = $this
      ->getGroup())) {
      throw new \LogicException('A group entity is required for creating a membership.');
    }
    $entity_type_id = $group
      ->getEntityTypeId();
    $bundle = $group
      ->bundle();
    if (!Og::isGroup($entity_type_id, $bundle)) {

      // Group is not valid.
      throw new \LogicException(sprintf('Entity type %s with ID %s is not an OG group.', $entity_type_id, $group
        ->id()));
    }

    // Check if the roles are valid.
    foreach ($this
      ->getRoles() as $role) {

      /** @var \Drupal\og\Entity\OgRole $role */

      // Make sure we don't save a membership for a non-member.
      if ($role
        ->getName() == OgRoleInterface::ANONYMOUS) {
        throw new \LogicException('Cannot save an OgMembership with reference to a non-member role.');
      }
      elseif ($role
        ->getName() == OgRoleInterface::AUTHENTICATED) {
        $this
          ->revokeRole($role);
      }
      elseif (!$this
        ->isRoleValid($role)) {
        throw new \LogicException(sprintf('The role with ID %s does not match the group type of the membership.', $role
          ->id()));
      }
    }

    // Check for an existing membership.
    $query = \Drupal::entityQuery('og_membership');
    $query
      ->condition('uid', $uid)
      ->condition('entity_id', $entity_id)
      ->condition('entity_type', $this
      ->get('entity_type')->value);
    if (!$this
      ->isNew()) {

      // Filter out this membership.
      $query
        ->condition('id', $this
        ->id(), '<>');
    }
    $count = $query
      ->range(0, 1)
      ->count()
      ->execute();
    if ($count) {
      throw new \LogicException(sprintf('An OG membership already exists for user ID %d and group of entity type %s and ID %s', $uid, $entity_type_id, $group
        ->id()));
    }
    parent::preSave($storage);
  }

  /**
   * {@inheritdoc}
   */
  public function save() {
    $result = parent::save();

    // Reset internal cache.
    Og::reset();
    return $result;
  }

  /**
   * {@inheritdoc}
   */
  protected function invalidateTagsOnSave($update) {
    parent::invalidateTagsOnSave($update);

    // A membership was created or updated: invalidate the membership list cache
    // tags of its group. An updated membership may start to appear in a group's
    // membership listings because it now meets those listings' filtering
    // requirements. A newly created membership may start to appear in listings
    // because it did not exist before.
    $group = $this
      ->getGroup();
    if (!empty($group)) {
      $tags = Cache::buildTags(OgMembershipInterface::GROUP_MEMBERSHIP_LIST_CACHE_TAG_PREFIX, $group
        ->getCacheTagsToInvalidate());
      Cache::invalidateTags($tags);
    }
  }

  /**
   * {@inheritdoc}
   */
  protected static function invalidateTagsOnDelete(EntityTypeInterface $entity_type, array $entities) {
    parent::invalidateTagsOnDelete($entity_type, $entities);

    // A membership was deleted: invalidate the list cache tags of its group
    // membership lists, so that any lists that contain the membership will be
    // recalculated.
    $tags = [];
    foreach ($entities as $entity) {
      if ($group = $entity
        ->getGroup()) {
        $tags = Cache::mergeTags(Cache::buildTags(OgMembershipInterface::GROUP_MEMBERSHIP_LIST_CACHE_TAG_PREFIX, $group
          ->getCacheTagsToInvalidate()), $tags);
      }
    }
    Cache::invalidateTags($tags);
  }

  /**
   * {@inheritdoc}
   */
  public static function create(array $values = []) {

    // Use the default membership type by default.
    $values += [
      'type' => OgMembershipInterface::TYPE_DEFAULT,
    ];
    return parent::create($values);
  }

  /**
   * {@inheritdoc}
   */
  public function isActive() : bool {
    return $this
      ->getState() === OgMembershipInterface::STATE_ACTIVE;
  }

  /**
   * {@inheritdoc}
   */
  public function isPending() : bool {
    return $this
      ->getState() === OgMembershipInterface::STATE_PENDING;
  }

  /**
   * {@inheritdoc}
   */
  public function isBlocked() : bool {
    return $this
      ->getState() === OgMembershipInterface::STATE_BLOCKED;
  }

  /**
   * {@inheritdoc}
   */
  public function isOwner() : bool {
    $group = $this
      ->getGroup();
    return $group instanceof EntityOwnerInterface && $group
      ->getOwnerId() == $this
      ->getOwnerId();
  }

  /**
   * Gets the value of a specific property of a field.
   *
   * Only the first delta can be accessed with this method.
   *
   * @todo Remove this once issue #2580551 is fixed.
   *
   * @see https://www.drupal.org/project/drupal/issues/2580551
   *
   * @param string $field_name
   *   The name of the field.
   * @param string $property
   *   The field property, "value" for many field types.
   *
   * @return mixed
   *   The value.
   */
  public function getFieldValue($field_name, $property) {

    // Attempt to get the value from the values directly if the field is not
    // initialized yet.
    if (!isset($this->fields[$field_name])) {
      $field_values = NULL;
      if (isset($this->values[$field_name][$this->activeLangcode])) {
        $field_values = $this->values[$field_name][$this->activeLangcode];
      }
      elseif (isset($this->values[$field_name][LanguageInterface::LANGCODE_DEFAULT])) {
        $field_values = $this->values[$field_name][LanguageInterface::LANGCODE_DEFAULT];
      }
      if ($field_values !== NULL) {

        // If there are field values, try to get the property value.
        // Configurable/Multi-value fields are stored differently, try accessing
        // with delta and property first, then without delta and last, if the
        // value is a scalar, just return that.
        if (isset($field_values[0][$property]) && is_array($field_values[0])) {
          return $field_values[0][$property];
        }
        elseif (isset($field_values[$property]) && is_array($field_values)) {
          return $field_values[$property];
        }
        elseif (!is_array($field_values)) {
          return $field_values;
        }
      }
    }

    // Fall back to access the property through the field object.
    return $this
      ->get($field_name)->{$property};
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheableDependencyTrait::$cacheContexts protected property Cache contexts.
CacheableDependencyTrait::$cacheMaxAge protected property Cache max-age.
CacheableDependencyTrait::$cacheTags protected property Cache tags.
CacheableDependencyTrait::setCacheability protected function Sets cacheability; useful for value object constructors.
ContentEntityBase::$activeLangcode protected property Language code identifying the entity active language.
ContentEntityBase::$defaultLangcode protected property Local cache for the default language code.
ContentEntityBase::$defaultLangcodeKey protected property The default langcode entity key.
ContentEntityBase::$enforceRevisionTranslationAffected protected property Whether the revision translation affected flag has been enforced.
ContentEntityBase::$entityKeys protected property Holds untranslatable entity keys such as the ID, bundle, and revision ID.
ContentEntityBase::$fieldDefinitions protected property Local cache for field definitions.
ContentEntityBase::$fields protected property The array of fields, each being an instance of FieldItemListInterface.
ContentEntityBase::$fieldsToSkipFromTranslationChangesCheck protected static property Local cache for fields to skip from the checking for translation changes.
ContentEntityBase::$isDefaultRevision protected property Indicates whether this is the default revision.
ContentEntityBase::$langcodeKey protected property The language entity key.
ContentEntityBase::$languages protected property Local cache for the available language objects.
ContentEntityBase::$loadedRevisionId protected property The loaded revision ID before the new revision was set.
ContentEntityBase::$newRevision protected property Boolean indicating whether a new revision should be created on save.
ContentEntityBase::$revisionTranslationAffectedKey protected property The revision translation affected entity key.
ContentEntityBase::$translatableEntityKeys protected property Holds translatable entity keys such as the label.
ContentEntityBase::$translationInitialize protected property A flag indicating whether a translation object is being initialized.
ContentEntityBase::$translations protected property An array of entity translation metadata.
ContentEntityBase::$validated protected property Whether entity validation was performed.
ContentEntityBase::$validationRequired protected property Whether entity validation is required before saving the entity.
ContentEntityBase::$values protected property The plain data values of the contained fields.
ContentEntityBase::access public function Checks data value access. Overrides EntityBase::access 1
ContentEntityBase::addTranslation public function Adds a new translation to the translatable object. Overrides TranslatableInterface::addTranslation
ContentEntityBase::bundle public function Gets the bundle of the entity. Overrides EntityBase::bundle
ContentEntityBase::bundleFieldDefinitions public static function Provides field definitions for a specific bundle. Overrides FieldableEntityInterface::bundleFieldDefinitions 4
ContentEntityBase::clearTranslationCache protected function Clear entity translation object cache to remove stale references.
ContentEntityBase::createDuplicate public function Creates a duplicate of the entity. Overrides EntityBase::createDuplicate 1
ContentEntityBase::get public function Gets a field item list. Overrides FieldableEntityInterface::get
ContentEntityBase::getEntityKey protected function Gets the value of the given entity key, if defined. 1
ContentEntityBase::getFieldDefinition public function Gets the definition of a contained field. Overrides FieldableEntityInterface::getFieldDefinition
ContentEntityBase::getFieldDefinitions public function Gets an array of field definitions of all contained fields. Overrides FieldableEntityInterface::getFieldDefinitions
ContentEntityBase::getFields public function Gets an array of all field item lists. Overrides FieldableEntityInterface::getFields
ContentEntityBase::getFieldsToSkipFromTranslationChangesCheck protected function Returns an array of field names to skip in ::hasTranslationChanges. 1
ContentEntityBase::getIterator public function
ContentEntityBase::getLanguages protected function
ContentEntityBase::getLoadedRevisionId public function Gets the loaded Revision ID of the entity. Overrides RevisionableInterface::getLoadedRevisionId
ContentEntityBase::getRevisionId public function Gets the revision identifier of the entity. Overrides RevisionableInterface::getRevisionId
ContentEntityBase::getTranslatableFields public function Gets an array of field item lists for translatable fields. Overrides FieldableEntityInterface::getTranslatableFields
ContentEntityBase::getTranslatedField protected function Gets a translated field.
ContentEntityBase::getTranslation public function Gets a translation of the data. Overrides TranslatableInterface::getTranslation
ContentEntityBase::getTranslationLanguages public function Returns the languages the data is translated to. Overrides TranslatableInterface::getTranslationLanguages
ContentEntityBase::getTranslationStatus public function Returns the translation status. Overrides TranslationStatusInterface::getTranslationStatus
ContentEntityBase::getUntranslated public function Returns the translatable object referring to the original language. Overrides TranslatableInterface::getUntranslated
ContentEntityBase::hasField public function Determines whether the entity has a field with the given name. Overrides FieldableEntityInterface::hasField
ContentEntityBase::hasTranslation public function Checks there is a translation for the given language code. Overrides TranslatableInterface::hasTranslation
ContentEntityBase::hasTranslationChanges public function Determines if the current translation of the entity has unsaved changes. Overrides TranslatableInterface::hasTranslationChanges
ContentEntityBase::id public function Gets the identifier. Overrides EntityBase::id
ContentEntityBase::initializeTranslation protected function Instantiates a translation object for an existing translation.
ContentEntityBase::isDefaultRevision public function Checks if this entity is the default revision. Overrides RevisionableInterface::isDefaultRevision
ContentEntityBase::isDefaultTranslation public function Checks whether the translation is the default one. Overrides TranslatableInterface::isDefaultTranslation
ContentEntityBase::isDefaultTranslationAffectedOnly public function Checks if untranslatable fields should affect only the default translation. Overrides TranslatableRevisionableInterface::isDefaultTranslationAffectedOnly
ContentEntityBase::isLatestRevision public function Checks if this entity is the latest revision. Overrides RevisionableInterface::isLatestRevision
ContentEntityBase::isLatestTranslationAffectedRevision public function Checks whether this is the latest revision affecting this translation. Overrides TranslatableRevisionableInterface::isLatestTranslationAffectedRevision
ContentEntityBase::isNewRevision public function Determines whether a new revision should be created on save. Overrides RevisionableInterface::isNewRevision
ContentEntityBase::isNewTranslation public function Checks whether the translation is new. Overrides TranslatableInterface::isNewTranslation
ContentEntityBase::isRevisionTranslationAffected public function Checks whether the current translation is affected by the current revision. Overrides TranslatableRevisionableInterface::isRevisionTranslationAffected
ContentEntityBase::isRevisionTranslationAffectedEnforced public function Checks if the revision translation affected flag value has been enforced. Overrides TranslatableRevisionableInterface::isRevisionTranslationAffectedEnforced
ContentEntityBase::isTranslatable public function Returns the translation support status. Overrides TranslatableInterface::isTranslatable
ContentEntityBase::isValidationRequired public function Checks whether entity validation is required before saving the entity. Overrides FieldableEntityInterface::isValidationRequired
ContentEntityBase::label public function Gets the label of the entity. Overrides EntityBase::label 2
ContentEntityBase::language public function Gets the language of the entity. Overrides EntityBase::language
ContentEntityBase::onChange public function Reacts to changes to a field. Overrides FieldableEntityInterface::onChange
ContentEntityBase::postCreate public function Acts on a created entity before hooks are invoked. Overrides EntityBase::postCreate
ContentEntityBase::postSave public function Acts on a saved entity before the insert or update hook is invoked. Overrides EntityBase::postSave 5
ContentEntityBase::preSaveRevision public function Acts on a revision before it gets saved. Overrides RevisionableInterface::preSaveRevision 2
ContentEntityBase::referencedEntities public function Gets a list of entities referenced by this entity. Overrides EntityBase::referencedEntities 1
ContentEntityBase::removeTranslation public function Removes the translation identified by the given language code. Overrides TranslatableInterface::removeTranslation
ContentEntityBase::set public function Sets a field value. Overrides FieldableEntityInterface::set
ContentEntityBase::setDefaultLangcode protected function Populates the local cache for the default language code.
ContentEntityBase::setNewRevision public function Enforces an entity to be saved as a new revision. Overrides RevisionableInterface::setNewRevision
ContentEntityBase::setRevisionTranslationAffected public function Marks the current revision translation as affected. Overrides TranslatableRevisionableInterface::setRevisionTranslationAffected
ContentEntityBase::setRevisionTranslationAffectedEnforced public function Enforces the revision translation affected flag value. Overrides TranslatableRevisionableInterface::setRevisionTranslationAffectedEnforced
ContentEntityBase::setValidationRequired public function Sets whether entity validation is required before saving the entity. Overrides FieldableEntityInterface::setValidationRequired
ContentEntityBase::toArray public function Gets an array of all property values. Overrides EntityBase::toArray
ContentEntityBase::updateFieldLangcodes protected function Updates language for already instantiated fields.
ContentEntityBase::updateLoadedRevisionId public function Updates the loaded Revision ID with the revision ID. Overrides RevisionableInterface::updateLoadedRevisionId
ContentEntityBase::updateOriginalValues public function Updates the original values with the interim changes.
ContentEntityBase::uuid public function Gets the entity UUID (Universally Unique Identifier). Overrides EntityBase::uuid
ContentEntityBase::validate public function Validates the currently set values. Overrides FieldableEntityInterface::validate
ContentEntityBase::wasDefaultRevision public function Checks whether the entity object was a default revision when it was saved. Overrides RevisionableInterface::wasDefaultRevision
ContentEntityBase::__clone public function Magic method: Implements a deep clone.
ContentEntityBase::__construct public function Constructs an Entity object. Overrides EntityBase::__construct
ContentEntityBase::__get public function Implements the magic method for getting object properties.
ContentEntityBase::__isset public function Implements the magic method for isset().
ContentEntityBase::__set public function Implements the magic method for setting object properties.
ContentEntityBase::__sleep public function Overrides EntityBase::__sleep
ContentEntityBase::__unset public function Implements the magic method for unset().
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function Aliased as: traitSleep 1
DependencySerializationTrait::__wakeup public function 2
EntityBase::$enforceIsNew protected property Boolean indicating whether the entity should be forced to be new.
EntityBase::$entityTypeId protected property The entity type.
EntityBase::$typedData protected property A typed data object wrapping this entity.
EntityBase::delete public function Deletes an entity permanently. Overrides EntityInterface::delete 2
EntityBase::enforceIsNew public function Enforces an entity to be new. Overrides EntityInterface::enforceIsNew
EntityBase::entityManager Deprecated protected function Gets the entity manager.
EntityBase::entityTypeBundleInfo protected function Gets the entity type bundle info service.
EntityBase::entityTypeManager protected function Gets the entity type manager.
EntityBase::getCacheContexts public function The cache contexts associated with this object. Overrides CacheableDependencyTrait::getCacheContexts
EntityBase::getCacheMaxAge public function The maximum age for which this object may be cached. Overrides CacheableDependencyTrait::getCacheMaxAge
EntityBase::getCacheTags public function The cache tags associated with this object. Overrides CacheableDependencyTrait::getCacheTags
EntityBase::getCacheTagsToInvalidate public function Returns the cache tags that should be used to invalidate caches. Overrides EntityInterface::getCacheTagsToInvalidate 2
EntityBase::getConfigDependencyKey public function Gets the key that is used to store configuration dependencies. Overrides EntityInterface::getConfigDependencyKey
EntityBase::getConfigDependencyName public function Gets the configuration dependency name. Overrides EntityInterface::getConfigDependencyName 1
EntityBase::getConfigTarget public function Gets the configuration target identifier for the entity. Overrides EntityInterface::getConfigTarget 1
EntityBase::getEntityType public function Gets the entity type definition. Overrides EntityInterface::getEntityType
EntityBase::getEntityTypeId public function Gets the ID of the type of the entity. Overrides EntityInterface::getEntityTypeId
EntityBase::getListCacheTagsToInvalidate protected function The list cache tags to invalidate for this entity.
EntityBase::getOriginalId public function Gets the original ID. Overrides EntityInterface::getOriginalId 1
EntityBase::getTypedData public function Gets a typed data object for this entity object. Overrides EntityInterface::getTypedData
EntityBase::hasLinkTemplate public function Indicates if a link template exists for a given key. Overrides EntityInterface::hasLinkTemplate
EntityBase::isNew public function Determines whether the entity is new. Overrides EntityInterface::isNew 2
EntityBase::languageManager protected function Gets the language manager.
EntityBase::link public function Deprecated way of generating a link to the entity. See toLink(). Overrides EntityInterface::link 1
EntityBase::linkTemplates protected function Gets an array link templates. 1
EntityBase::load public static function Loads an entity. Overrides EntityInterface::load
EntityBase::loadMultiple public static function Loads one or more entities. Overrides EntityInterface::loadMultiple
EntityBase::postDelete public static function Acts on deleted entities before the delete hook is invoked. Overrides EntityInterface::postDelete 16
EntityBase::postLoad public static function Acts on loaded entities. Overrides EntityInterface::postLoad 2
EntityBase::preCreate public static function Changes the values of an entity before it is created. Overrides EntityInterface::preCreate 5
EntityBase::preDelete public static function Acts on entities before they are deleted and before hooks are invoked. Overrides EntityInterface::preDelete 4
EntityBase::setOriginalId public function Sets the original ID. Overrides EntityInterface::setOriginalId 1
EntityBase::toLink public function Generates the HTML for a link to this entity. Overrides EntityInterface::toLink
EntityBase::toUrl public function Gets the URL object for the entity. Overrides EntityInterface::toUrl 2
EntityBase::uriRelationships public function Gets a list of URI relationships supported by this entity. Overrides EntityInterface::uriRelationships
EntityBase::url public function Gets the public URL for this entity. Overrides EntityInterface::url 2
EntityBase::urlInfo public function Gets the URL object for the entity. Overrides EntityInterface::urlInfo 1
EntityBase::urlRouteParameters protected function Gets an array of placeholders for this entity. 2
EntityBase::uuidGenerator protected function Gets the UUID generator.
EntityChangesDetectionTrait::getFieldsToSkipFromTranslationChangesCheck protected function Returns an array of field names to skip when checking for changes. Aliased as: traitGetFieldsToSkipFromTranslationChangesCheck
OgMembership::addRole public function Adds a role to the user membership. Overrides OgMembershipInterface::addRole
OgMembership::baseFieldDefinitions public static function Provides base field definitions for an entity type. Overrides ContentEntityBase::baseFieldDefinitions
OgMembership::create public static function Constructs a new entity object, without permanently saving it. Overrides EntityBase::create
OgMembership::getCreatedTime public function Gets the membership creation timestamp. Overrides OgMembershipInterface::getCreatedTime
OgMembership::getFieldValue public function Gets the value of a specific property of a field.
OgMembership::getGroup public function Gets the group associated with the membership. Overrides OgMembershipInterface::getGroup
OgMembership::getGroupBundle public function Gets the group entity bundle. Overrides OgMembershipInterface::getGroupBundle
OgMembership::getGroupEntityType public function Gets the group entity type. Overrides OgMembershipInterface::getGroupEntityType
OgMembership::getGroupId public function Gets the group entity ID. Overrides OgMembershipInterface::getGroupId
OgMembership::getOwner public function Returns the entity owner's user entity. Overrides EntityOwnerInterface::getOwner
OgMembership::getOwnerId public function Returns the entity owner's user ID. Overrides EntityOwnerInterface::getOwnerId
OgMembership::getRoles public function Gets all the referenced OG roles. Overrides OgMembershipInterface::getRoles
OgMembership::getRolesIds public function Gets all the referenced OG role IDs. Overrides OgMembershipInterface::getRolesIds
OgMembership::getState public function Gets the membership state. Overrides OgMembershipInterface::getState
OgMembership::getType public function Gets the membership type. Overrides OgMembershipInterface::getType
OgMembership::hasGroup protected function Checks if a group has already been populated on the membership.
OgMembership::hasPermission public function Checks if the user has a permission inside the group. Overrides OgMembershipInterface::hasPermission
OgMembership::hasRole public function Checks if the membership has the role with the given ID. Overrides OgMembershipInterface::hasRole
OgMembership::invalidateTagsOnDelete protected static function Invalidates an entity's cache tags upon delete. Overrides EntityBase::invalidateTagsOnDelete
OgMembership::invalidateTagsOnSave protected function Invalidates an entity's cache tags upon save. Overrides EntityBase::invalidateTagsOnSave
OgMembership::isActive public function Returns TRUE if the OG membership is active. Overrides OgMembershipInterface::isActive
OgMembership::isBlocked public function Returns TRUE if the OG membership is blocked. Overrides OgMembershipInterface::isBlocked
OgMembership::isOwner public function Returns TRUE if the OG membership belongs to the group owner. Overrides OgMembershipInterface::isOwner
OgMembership::isPending public function Returns TRUE if the OG membership is pending. Overrides OgMembershipInterface::isPending
OgMembership::isRoleValid public function Returns whether the given role is valid for this membership. Overrides OgMembershipInterface::isRoleValid
OgMembership::preSave public function Acts on an entity before the presave hook is invoked. Overrides ContentEntityBase::preSave
OgMembership::revokeRole public function Revokes a role from the OG membership. Overrides OgMembershipInterface::revokeRole
OgMembership::revokeRoleById public function Revokes a role from the OG membership. Overrides OgMembershipInterface::revokeRoleById
OgMembership::save public function Saves an entity permanently. Overrides EntityBase::save
OgMembership::setCreatedTime public function Sets the membership creation timestamp. Overrides OgMembershipInterface::setCreatedTime
OgMembership::setGroup public function Sets the group associated with the membership. Overrides OgMembershipInterface::setGroup
OgMembership::setOwner public function Sets the entity owner's user entity. Overrides EntityOwnerInterface::setOwner
OgMembership::setOwnerId public function Sets the entity owner's user ID. Overrides EntityOwnerInterface::setOwnerId
OgMembership::setRoles public function Sets the group's roles for the current user group membership. Overrides OgMembershipInterface::setRoles
OgMembership::setState public function Sets the membership state. Overrides OgMembershipInterface::setState
OgMembershipInterface::ALL_STATES constant An array containing all possible group membership states.
OgMembershipInterface::GROUP_MEMBERSHIP_LIST_CACHE_TAG_PREFIX constant The prefix that is used to identify group membership list cache tags.
OgMembershipInterface::REQUEST_FIELD constant The name of the user's request field in the default group membership type.
OgMembershipInterface::STATE_ACTIVE constant Define active group content states.
OgMembershipInterface::STATE_BLOCKED constant Define blocked group content states. The user is rejected from the group.
OgMembershipInterface::STATE_PENDING constant Define pending group content states.
OgMembershipInterface::TYPE_DEFAULT constant The default group membership type that is the bundle of group membership.
RefinableCacheableDependencyTrait::addCacheableDependency public function 1
RefinableCacheableDependencyTrait::addCacheContexts public function
RefinableCacheableDependencyTrait::addCacheTags public function
RefinableCacheableDependencyTrait::mergeCacheMaxAge public function
SynchronizableEntityTrait::$isSyncing protected property Whether this entity is being created, updated or deleted through a synchronization process.
SynchronizableEntityTrait::isSyncing public function
SynchronizableEntityTrait::setSyncing public function
TranslationStatusInterface::TRANSLATION_CREATED constant Status code identifying a newly created translation.
TranslationStatusInterface::TRANSLATION_EXISTING constant Status code identifying an existing translation.
TranslationStatusInterface::TRANSLATION_REMOVED constant Status code identifying a removed translation.