You are here

public function MapProviderBase::validateMapFeatureForms in Geolocation Field 8.3

Same name and namespace in other branches
  1. 8.2 src/MapProviderBase.php \Drupal\geolocation\MapProviderBase::validateMapFeatureForms()

Validate form.

Parameters

array $element: Form element to check.

\Drupal\Core\Form\FormStateInterface $form_state: Current form state.

array $form: Current form.

File

src/MapProviderBase.php, line 234

Class

MapProviderBase
Provide Map Provider Base class.

Namespace

Drupal\geolocation

Code

public function validateMapFeatureForms(array $element, FormStateInterface $form_state, array $form) {
  $values = $form_state
    ->getValues();
  $parents = [];
  if (!empty($element['#parents'])) {
    $parents = $element['#parents'];
    $values = NestedArray::getValue($values, $parents);
  }
  foreach ($this->mapFeatureManager
    ->getMapFeaturesByMapType($this
    ->getPluginId()) as $feature_id => $feature_definition) {
    if (!empty($values[$feature_id]['enabled'])) {
      $feature = $this->mapFeatureManager
        ->getMapFeature($feature_id, []);
      if ($feature && method_exists($feature, 'validateSettingsForm')) {
        $feature_parents = $parents;
        array_push($feature_parents, $feature_id, 'settings');
        $feature
          ->validateSettingsForm(empty($values[$feature_id]['settings']) ? [] : $values[$feature_id]['settings'], $form_state, $feature_parents);
      }
    }
  }
}