You are here

public function Post::getVisibility in Open Social 10.3.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_post/src/Entity/Post.php \Drupal\social_post\Entity\Post::getVisibility()
  2. 8.4 modules/social_features/social_post/src/Entity/Post.php \Drupal\social_post\Entity\Post::getVisibility()
  3. 8.5 modules/social_features/social_post/src/Entity/Post.php \Drupal\social_post\Entity\Post::getVisibility()
  4. 8.6 modules/social_features/social_post/src/Entity/Post.php \Drupal\social_post\Entity\Post::getVisibility()
  5. 8.7 modules/social_features/social_post/src/Entity/Post.php \Drupal\social_post\Entity\Post::getVisibility()
  6. 8.8 modules/social_features/social_post/src/Entity/Post.php \Drupal\social_post\Entity\Post::getVisibility()
  7. 10.0.x modules/social_features/social_post/src/Entity/Post.php \Drupal\social_post\Entity\Post::getVisibility()
  8. 10.1.x modules/social_features/social_post/src/Entity/Post.php \Drupal\social_post\Entity\Post::getVisibility()
  9. 10.2.x modules/social_features/social_post/src/Entity/Post.php \Drupal\social_post\Entity\Post::getVisibility()

File

modules/social_features/social_post/src/Entity/Post.php, line 167

Class

Post
Defines the Post entity.

Namespace

Drupal\social_post\Entity

Code

public function getVisibility() {
  $allowed_values = $this
    ->getPostVisibilityAllowedValues();
  if ($this
    ->hasField('field_visibility')) {
    foreach ($allowed_values as $key => $allowed_value) {
      if ($this->field_visibility->value == $allowed_value['value']) {

        // Default visibility options.
        $visibility = $this
          ->getDefaultVisibilityByLabel($allowed_value['label']);

        // If default visibility doesn't exist it means we use the role
        // as visibility option and we should set the role id as visibility.
        if (!$visibility) {
          $roles = $this
            ->entityTypeManager()
            ->getStorage('user_role')
            ->getQuery()
            ->condition('label', $allowed_value['label'])
            ->execute();
          $role_id = reset($roles);

          // If role_id is empty it means we have an uninspected visibility
          // option, because this option does not default and not from
          // the role.
          if (!empty($role_id)) {
            $visibility = $role_id;
          }
        }
      }
    }
  }
  return $visibility;
}