You are here

class LinkAddressfield in Conditional Fields 8

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

Provides states handler for links provided by the Addressfield module.

Plugin annotation


@ConditionalFieldsHandler(
  id = "states_handler_address_default",
)

Hierarchy

Expanded class hierarchy of LinkAddressfield

File

src/Plugin/conditional_fields/handler/extra_contrib/LinkAddressfield.php, line 15

Namespace

Drupal\conditional_fields\Plugin\conditional_fields\handler\extra_contrib
View source
class LinkAddressfield extends ConditionalFieldsHandlerBase {

  /**
   * {@inheritdoc}
   */
  public function statesHandler($field, $field_info, $options) {
    $state = [];
    if ($options['values_set'] != ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_WIDGET) {
      return $state;
    }
    $regex = $options['values_set'] == ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_REGEX;
    $keys = [];
    if ($field['#handlers']['address']) {
      $keys += [
        'country',
        'thoroughfare',
        'premise',
        'postal_code',
        'locality',
        'administrative_area',
      ];
    }
    if ($field['#handlers']['organisation']) {
      $keys += [
        'organisation_name',
      ];
    }
    if ($field['#handlers']['name-oneline']) {
      $keys += [
        'name_line',
      ];
    }
    elseif ($field['#handlers']['name-full']) {
      $keys += [
        'first_name',
        'last_name',
      ];
    }
    $addressfield_selectors = [];
    foreach ($keys as $key) {
      $addressfield_selectors[str_replace('%key', $key, $options['selector'])] = [
        'value' => $regex ? $options['value'] : $options['value'][0][$key],
      ];
    }
    $state = [
      $options['state'] => $addressfield_selectors,
    ];
    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
LinkAddressfield::statesHandler public function Executes states handler according to conditional fields settings. Overrides ConditionalFieldsHandlersPluginInterface::statesHandler