Same name in other branches
- 8.x-2.x src/FieldStateBase.php \Drupal\field_states_ui\FieldStateBase::applyState()
Overrides FieldStateInterface::applyState
Fichier
-
src/
FieldStateBase.php, line 57
Classe
- FieldStateBase
- Provides a base class for field staes.
Namespace
Drupal\field_states_uiCode
public function applyState(array &$states, FormStateInterface $form_state, array $context, array $element, array $parents = NULL) {
$target_field = $form_state->getFormObject()
->getFormDisplay($form_state)
->getComponent($this->configuration['target']);
// If dealing with a field on an Inline Entity Form or a Field Collection
// have to include the field parents in the selector.
if (!empty($parents)) {
$target = array_shift($parents) . '[' . implode('][', $parents) . '][' . $this->configuration['target'] . ']';
}
else {
$target = $this->configuration['target'];
}
switch ($target_field['type']) {
case 'options_select':
$selector = "select[name^='{$target}']";
break;
default:
$selector = ":input[name^='{$target}']";
break;
}
$states[$this->pluginDefinition['id']][] = [
$selector => [
$this->configuration['comparison'] => $this->configuration['value'],
],
];
return TRUE;
}