You are here

public function LinkField::statesHandler in Conditional Fields 4.x

Same name and namespace in other branches
  1. 8 src/Plugin/conditional_fields/handler/LinkField.php \Drupal\conditional_fields\Plugin\conditional_fields\handler\LinkField::statesHandler()

@todo Provide possibility to create states with pair URL and title. Only states for URL currently supported.

Overrides ConditionalFieldsHandlersPluginInterface::statesHandler

File

src/Plugin/conditional_fields/handler/LinkField.php, line 24

Class

LinkField
Provides states handler for links provided by the Link module.

Namespace

Drupal\conditional_fields\Plugin\conditional_fields\handler

Code

public function statesHandler($field, $field_info, $options) {
  $state = [];
  switch ($options['values_set']) {
    case ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_WIDGET:
      $values_array = [];

      // Get an array of values or string for comparing.
      $uri = $this
        ->getWidgetValue($options['value_form']);
      $values = static::getUriAsDisplayableString($uri);
      if (is_array($values)) {
        foreach ($values as $value) {
          $values_array[] = [
            'value' => $value,
          ];
        }
      }
      else {
        $values_array = [
          $options['condition'] => $values,
        ];
      }
      $state[$options['state']][$options['selector']] = $values_array;
      break;
    case ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_REGEX:
    case ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_XOR:
    case ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_OR:

      // Works, there are not implementation here.
      break;
    case ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_AND:

      // @todo Send field settings to statesHandler to check field cardinality.
      break;
  }
  return $state;
}