protected function ActivityLoggerFactory::createFieldInstances in Open Social 8
Same name and namespace in other branches
- 8.9 modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createFieldInstances()
- 8.2 modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createFieldInstances()
- 8.3 modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createFieldInstances()
- 8.4 modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createFieldInstances()
- 8.5 modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createFieldInstances()
- 8.6 modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createFieldInstances()
- 8.7 modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createFieldInstances()
- 8.8 modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createFieldInstances()
- 10.3.x modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createFieldInstances()
- 10.0.x modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createFieldInstances()
- 10.1.x modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createFieldInstances()
- 10.2.x modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createFieldInstances()
Create field instances.
Parameters
string $message_type: The typeof message.
array $fields: The data to insert in the field instances.
1 call to ActivityLoggerFactory::createFieldInstances()
- ActivityLoggerFactory::createMessages in modules/
custom/ activity_logger/ src/ Service/ ActivityLoggerFactory.php - Create message entities.
File
- modules/
custom/ activity_logger/ src/ Service/ ActivityLoggerFactory.php, line 137
Class
- ActivityLoggerFactory
- Class ActivityLoggerFactory.
Namespace
Drupal\activity_logger\ServiceCode
protected function createFieldInstances($message_type, array $fields) {
foreach ($fields as $field) {
$id = 'message.' . $message_type . '.' . $field['name'];
$config_storage = \Drupal::entityTypeManager()
->getStorage('field_config');
// Create field instances if they do not exists.
if ($config_storage
->load($id) === NULL) {
$field_instance = [
'langcode' => 'en',
'status' => TRUE,
'config' => [
'field.storage.message.' . $field['name'],
'message.template.' . $message_type,
],
'module' => [
'options',
],
'id' => $id,
'field_name' => $field['name'],
'entity_type' => 'message',
'bundle' => $message_type,
'label' => '',
'description' => '',
'required' => FALSE,
'translatable' => FALSE,
'default_value' => [],
'default_value_callback' => '',
'field_type' => $field['type'],
];
if ($field['type'] === 'list_string') {
$field_instance['module'] = [
'options',
];
$field_instance['settings'] = [];
}
elseif ($field['type'] === 'dynamic_entity_reference') {
$field_instance['module'] = [
'dynamic_entity_reference',
];
$field_instance['settings'] = [];
}
$config_storage
->create($field_instance)
->save();
}
}
}