public function EntityReferenceHandlerBase::validateHandlerSettings in CMS Content Sync 8
Same name and namespace in other branches
- 2.1.x src/Plugin/EntityReferenceHandlerBase.php \Drupal\cms_content_sync\Plugin\EntityReferenceHandlerBase::validateHandlerSettings()
- 2.0.x src/Plugin/EntityReferenceHandlerBase.php \Drupal\cms_content_sync\Plugin\EntityReferenceHandlerBase::validateHandlerSettings()
Validate the settings defined above. $form and $form_state are the same as in the Form API. $settings_key is the index at $form['sync_entities'] for this handler instance.
Parameters
$settings_key:
$current_values:
Return value
mixed
Overrides FieldHandlerBase::validateHandlerSettings
File
- src/
Plugin/ EntityReferenceHandlerBase.php, line 111
Class
- EntityReferenceHandlerBase
- Providing a base implementation for any reference field type.
Namespace
Drupal\cms_content_sync\PluginCode
public function validateHandlerSettings(array &$form, FormStateInterface $form_state, $settings_key, $current_values) {
if (!$this
->shouldPushReferencedEntities() && !$this
->shouldEmbedReferencedEntities()) {
return;
}
$reference_types = $this
->getReferencedEntityTypes();
foreach ($current_values['sync_entities'] as $key => $config) {
// Ignore field definitions.
if (1 != substr_count($key, '-')) {
continue;
}
// Ignore ignored configs.
if (Flow::HANDLER_IGNORE == $config['handler']) {
continue;
}
list($entity_type_id) = explode('-', $key);
$index = array_search($entity_type_id, $reference_types);
// Ignore configs that don't match our entity type.
if (false === $index) {
continue;
}
// One has an push handler, so we can ignore this.
unset($reference_types[$index]);
}
if (!count($reference_types)) {
return;
}
// We are just about to load this element, so we don't have any form element available yet. Validation will be
// triggered again when the form is submitted.
if (empty($form[$this->entityTypeName][$this->bundleName]['fields'][$settings_key]['handler'])) {
return;
}
// No fitting handler was found- inform the user that he's missing some
// configuration.
if ($this
->forcePushingReferencedEntities() || $this
->forceEmbeddingReferencedEntities()) {
$element =& $form[$this->entityTypeName][$this->bundleName]['fields'][$settings_key]['handler'];
}
else {
$element =& $form[$this->entityTypeName][$this->bundleName]['fields'][$settings_key]['handler_settings']['export_referenced_entities'];
}
foreach ($reference_types as $type) {
$form_state
->setError($element, t('You want to push %referenced\'s that are referenced in %source automatically, but you have not defined any handler for this entity type. Please scroll to the bundles of this entity type, add a handler and set "push" to "referenced" there.', [
'%referenced' => $type,
'%source' => $settings_key,
]));
}
}