You are here

public function ContentEntityAggregatorSensorPlugin::validateConfigurationForm in Monitoring 8

Form validation handler.

Parameters

array $form: An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Overrides SensorPluginBase::validateConfigurationForm

File

src/Plugin/monitoring/SensorPlugin/ContentEntityAggregatorSensorPlugin.php, line 591
Contains \Drupal\monitoring\Plugin\monitoring\SensorPlugin\ContentEntityAggregatorSensorPlugin.

Class

ContentEntityAggregatorSensorPlugin
Content entity database aggregator.

Namespace

Drupal\monitoring\Plugin\monitoring\SensorPlugin

Code

public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
  parent::validateConfigurationForm($form, $form_state);
  $field_name = $form_state
    ->getValue(array(
    'settings',
    'aggregation',
    'time_interval_field',
  ));
  $entity_type_id = $form_state
    ->getValue(array(
    'settings',
    'entity_type',
  ));
  if (!empty($field_name) && !empty($entity_type_id)) {

    // @todo instead of validate, switch to a form select.
    $entity_info = $this->entityFieldManager
      ->getFieldStorageDefinitions($entity_type_id);
    $data_type = NULL;
    if (!empty($entity_info[$field_name])) {
      $data_type = $entity_info[$field_name]
        ->getPropertyDefinition('value')
        ->getDataType();
    }
    if ($data_type != 'timestamp') {
      $form_state
        ->setErrorByName('settings][aggregation][time_interval_field', t('The specified time interval field %name does not exist or is not type timestamp.', array(
        '%name' => $field_name,
      )));
    }
  }
}