function activity_creator_set_entity_view_mode in Open Social 10.3.x
Same name and namespace in other branches
- 8.9 modules/custom/activity_creator/activity_creator.module \activity_creator_set_entity_view_mode()
- 8.8 modules/custom/activity_creator/activity_creator.module \activity_creator_set_entity_view_mode()
- 10.0.x modules/custom/activity_creator/activity_creator.module \activity_creator_set_entity_view_mode()
- 10.1.x modules/custom/activity_creator/activity_creator.module \activity_creator_set_entity_view_mode()
- 10.2.x modules/custom/activity_creator/activity_creator.module \activity_creator_set_entity_view_mode()
Set the view mode for the activity entity reference for an entity type.
Provides no validation on the validity of the entity type id or the view mode id.
Parameters
string $entity_type_id: The entity type for which to change the view mode.
string $view_mode_id: The view mode to use in the activity entity reference field.
7 calls to activity_creator_set_entity_view_mode()
- social_comment_install in modules/
social_features/ social_comment/ social_comment.install - Implements hook_install().
- social_comment_update_8801 in modules/
social_features/ social_comment/ social_comment.install - Set the view mode to use when shown in activities.
- social_core_update_8803 in modules/
social_features/ social_core/ social_core.install - Set the view mode for nodes to use when shown in activities.
- social_group_install in modules/
social_features/ social_group/ social_group.install - Implements hook_install().
- social_node_install in modules/
social_features/ social_node/ social_node.install - Implements hook_install().
File
- modules/
custom/ activity_creator/ activity_creator.module, line 408 - Activity Creator module file.
Code
function activity_creator_set_entity_view_mode(string $entity_type_id, string $view_mode_id) {
/** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $activity_display */
$activity_display = \Drupal::service('entity_type.manager')
->getStorage('entity_view_display')
->load('activity.activity.default');
$field = $activity_display
->getComponent('field_activity_entity');
$field['settings'][$entity_type_id]['view_mode'] = $view_mode_id;
$activity_display
->setComponent('field_activity_entity', $field)
->save();
}