public function AcquiadamAsset::submitConfigurationForm in Media: Acquia DAM 8
Form submission handler.
Parameters
array $form: An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().
Overrides MediaSourceBase::submitConfigurationForm
File
- src/
Plugin/ media/ Source/ AcquiadamAsset.php, line 119
Class
- AcquiadamAsset
- Provides media type plugin for Acquia DAM assets.
Namespace
Drupal\media_acquiadam\Plugin\media\SourceCode
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$submitted_config = array_intersect_key($form_state
->getValues(), $this->configuration);
foreach ($submitted_config as $config_key => $config_value) {
$this->configuration[$config_key] = $config_value;
}
// For consistency, always use the default source_field field name.
$default_field_name = $this
->defaultConfiguration()['source_field'];
// Check if it already exists so it can be used as a shared field.
$storage = $this->entityTypeManager
->getStorage('field_storage_config');
$existing_source_field = $storage
->load('media.' . $default_field_name);
// Set or create the source field.
if ($existing_source_field) {
// If the default field already exists, return the default field name.
$this->configuration['source_field'] = $default_field_name;
}
else {
// Default source field name does not exist, so create a new one.
$field_storage = $this
->createSourceFieldStorage();
$field_storage
->save();
$this->configuration['source_field'] = $field_storage
->getName();
}
}