You are here

function rng_add_event_field_config in RNG - Events and Registrations 8

Same name and namespace in other branches
  1. 8.2 rng.field.defaults.inc \rng_add_event_field_config()
  2. 3.x rng.field.defaults.inc \rng_add_event_field_config()

Return value

\Drupal\Core\Field\FieldConfigInterface

2 calls to rng_add_event_field_config()
EventType::postSave in src/Entity/EventType.php
Acts on a saved entity before the insert or update hook is invoked.
EventTypeFieldMappingForm::createField in src/Form/EventTypeFieldMappingForm.php
Form submission function to respond to the create field button.

File

./rng.field.defaults.inc, line 181
Creates field config if they do not exist.

Code

function rng_add_event_field_config($field_name, $entity_type, $bundle = NULL) {
  if ($field = FieldConfig::loadByName($entity_type, $bundle, $field_name)) {
    return NULL;
  }
  $definition = rng_event_field_config_definition($field_name);
  if (!empty($definition)) {
    $field = entity_create('field_config', array(
      'field_name' => $field_name,
      'entity_type' => $entity_type,
      'bundle' => $bundle,
    ) + $definition);
    $field
      ->save();
  }
  return $field;
}