public function DemoNode::createFollow in Open Social 8
Same name and namespace in other branches
- 8.9 modules/custom/social_demo/src/DemoNode.php \Drupal\social_demo\DemoNode::createFollow()
- 8.2 modules/custom/social_demo/src/DemoNode.php \Drupal\social_demo\DemoNode::createFollow()
- 8.3 modules/custom/social_demo/src/DemoNode.php \Drupal\social_demo\DemoNode::createFollow()
- 8.4 modules/custom/social_demo/src/DemoNode.php \Drupal\social_demo\DemoNode::createFollow()
- 8.5 modules/custom/social_demo/src/DemoNode.php \Drupal\social_demo\DemoNode::createFollow()
- 8.6 modules/custom/social_demo/src/DemoNode.php \Drupal\social_demo\DemoNode::createFollow()
- 8.7 modules/custom/social_demo/src/DemoNode.php \Drupal\social_demo\DemoNode::createFollow()
- 8.8 modules/custom/social_demo/src/DemoNode.php \Drupal\social_demo\DemoNode::createFollow()
- 10.3.x modules/custom/social_demo/src/DemoNode.php \Drupal\social_demo\DemoNode::createFollow()
- 10.0.x modules/custom/social_demo/src/DemoNode.php \Drupal\social_demo\DemoNode::createFollow()
- 10.1.x modules/custom/social_demo/src/DemoNode.php \Drupal\social_demo\DemoNode::createFollow()
- 10.2.x modules/custom/social_demo/src/DemoNode.php \Drupal\social_demo\DemoNode::createFollow()
The function that checks and creates a follow on an entity.
Parameters
\Drupal\Core\Entity\Entity $entity: The related entity.
array $uuids: The array containing uuids.
1 call to DemoNode::createFollow()
- DemoNode::createContent in modules/
custom/ social_demo/ src/ DemoNode.php - Creates content.
File
- modules/
custom/ social_demo/ src/ DemoNode.php, line 199
Class
- DemoNode
- Class DemoNode.
Namespace
Drupal\social_demoCode
public function createFollow(Entity $entity, array $uuids) {
foreach ($uuids as $uuid) {
// Load the user(s) by the given uuid(s).
$account = $this
->loadByUuid('user', $uuid);
$properties = [
'uid' => $account
->id(),
'entity_type' => 'node',
'entity_id' => $entity
->id(),
'flag_id' => 'follow_content',
];
// Check the current flaggings.
$flaggings = \Drupal::entityTypeManager()
->getStorage('flagging')
->loadByProperties($properties);
$flagging = reset($flaggings);
// If the user is already following, then nothing happens.
// Else we create the flagging with the properties above.
if (empty($flagging)) {
$flagging = Flagging::create($properties);
if ($flagging) {
$flagging
->save();
}
}
}
}