You are here

class LanguageSelect in Conditional Fields 8

Same name and namespace in other branches
  1. 4.x src/Plugin/conditional_fields/handler/LanguageSelect.php \Drupal\conditional_fields\Plugin\conditional_fields\handler\LanguageSelect

Provides states handler for language select list.

Plugin annotation


@ConditionalFieldsHandler(
  id = "states_handler_language_select",
)

Hierarchy

Expanded class hierarchy of LanguageSelect

File

src/Plugin/conditional_fields/handler/LanguageSelect.php, line 15

Namespace

Drupal\conditional_fields\Plugin\conditional_fields\handler
View source
class LanguageSelect extends ConditionalFieldsHandlerBase {

  /**
   * {@inheritdoc}
   */
  public function statesHandler($field, $field_info, $options) {
    $state = [];
    $select_states = [];
    switch ($options['values_set']) {
      case ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_WIDGET:
        $state[$options['state']][$options['selector']] = [
          'value' => $this
            ->getWidgetValue($options['value_form']),
        ];
        break;
      case ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_AND:
        break;
      case ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_XOR:
        $select_states[$options['state']][] = [
          $options['selector'] => [
            $options['condition'] => [
              'xor' => $options['values'],
            ],
          ],
        ];
        $state = $select_states;
        break;
      case ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_REGEX:
        $select_states[$options['state']][] = [
          $options['selector'] => [
            $options['condition'] => [
              'regex' => $options['regex'],
            ],
          ],
        ];
        $state = $select_states;
        break;
      case ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_NOT:
        $options['state'] = '!' . $options['state'];
      case ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_OR:
        foreach ($options['values'] as $value) {
          $select_states[$options['state']][] = [
            $options['selector'] => [
              $options['condition'] => empty($regex) ? [
                $value,
              ] : $options['value'],
            ],
          ];
        }
        $state = $select_states;
        break;
    }
    return $state;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConditionalFieldsHandlerBase::getConditionValues public function Get values form the condition options Overrides ConditionalFieldsHandlersPluginInterface::getConditionValues
ConditionalFieldsHandlerBase::getWidgetValue public function Get values from widget settings for plugin. Overrides ConditionalFieldsHandlersPluginInterface::getWidgetValue 5
LanguageSelect::statesHandler public function Executes states handler according to conditional fields settings. Overrides ConditionalFieldsHandlersPluginInterface::statesHandler