You are here

public static function ViewfieldItem::fieldSettingsFormValidate in Viewfield 8.3

Form API callback.

Requires that field defaults be supplied when the 'force_default' option is checked.

This function is assigned as an #element_validate callback in fieldSettingsForm().

Overrides EntityReferenceItem::fieldSettingsFormValidate

File

src/Plugin/Field/FieldType/ViewfieldItem.php, line 152

Class

ViewfieldItem
Plugin implementation of the 'viewfield' field type.

Namespace

Drupal\viewfield\Plugin\Field\FieldType

Code

public static function fieldSettingsFormValidate(array $form, FormStateInterface $form_state) {
  $settings = $form_state
    ->getValue('settings');
  if ($settings['force_default']) {
    $default_value = $form_state
      ->getValue('default_value_input');
    $field_name = $form_state
      ->getFormObject()
      ->getEntity()
      ->getName();
    if (empty($default_value[$field_name][0]['target_id']) || $default_value[$field_name][0]['target_id'] == '_none') {
      $form_state
        ->setErrorByName('default_value_input', t('%title requires a default value.', [
        '%title' => $form['force_default']['#title'],
      ]));
    }
  }
}