You are here

protected function ActivityLoggerFactory::createFieldInstances in Open Social 8

Same name and namespace in other branches
  1. 8.9 modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createFieldInstances()
  2. 8.2 modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createFieldInstances()
  3. 8.3 modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createFieldInstances()
  4. 8.4 modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createFieldInstances()
  5. 8.5 modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createFieldInstances()
  6. 8.6 modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createFieldInstances()
  7. 8.7 modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createFieldInstances()
  8. 8.8 modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createFieldInstances()
  9. 10.3.x modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createFieldInstances()
  10. 10.0.x modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createFieldInstances()
  11. 10.1.x modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createFieldInstances()
  12. 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\Service

Code

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();
    }
  }
}