public function Post::setVisibility in Open Social 10.3.x
Same name and namespace in other branches
- 8.9 modules/social_features/social_post/src/Entity/Post.php \Drupal\social_post\Entity\Post::setVisibility()
- 8.4 modules/social_features/social_post/src/Entity/Post.php \Drupal\social_post\Entity\Post::setVisibility()
- 8.5 modules/social_features/social_post/src/Entity/Post.php \Drupal\social_post\Entity\Post::setVisibility()
- 8.6 modules/social_features/social_post/src/Entity/Post.php \Drupal\social_post\Entity\Post::setVisibility()
- 8.7 modules/social_features/social_post/src/Entity/Post.php \Drupal\social_post\Entity\Post::setVisibility()
- 8.8 modules/social_features/social_post/src/Entity/Post.php \Drupal\social_post\Entity\Post::setVisibility()
- 10.0.x modules/social_features/social_post/src/Entity/Post.php \Drupal\social_post\Entity\Post::setVisibility()
- 10.1.x modules/social_features/social_post/src/Entity/Post.php \Drupal\social_post\Entity\Post::setVisibility()
- 10.2.x modules/social_features/social_post/src/Entity/Post.php \Drupal\social_post\Entity\Post::setVisibility()
File
- modules/
social_features/ social_post/ src/ Entity/ Post.php, line 260
Class
- Post
- Defines the Post entity.
Namespace
Drupal\social_post\EntityCode
public function setVisibility($visibility) {
$allowed_values = $this
->getPostVisibilityAllowedValues();
$visibility_label = $this
->getDefaultVisibilityByLabel($visibility, TRUE);
if (!$visibility_label) {
/** @var \Drupal\user\RoleInterface $role */
$role = $this
->entityTypeManager()
->getStorage('user_role')
->load($visibility);
if ($role instanceof RoleInterface) {
foreach ($allowed_values as $key => $value) {
if ($value['label'] === $role
->label()) {
$this
->set('field_visibility', $key);
}
}
}
}
else {
foreach ($allowed_values as $key => $allowed_value) {
if ($visibility_label == $allowed_value['label']) {
$this
->set('field_visibility', (int) $allowed_value['value']);
}
}
}
return $this;
}