public function TwitterWidgetWidget::validate in Twitter Profile Widget 3.x
Same name and namespace in other branches
- 8.2 src/Plugin/Field/FieldWidget/TwitterWidgetWidget.php \Drupal\twitter_profile_widget\Plugin\Field\FieldWidget\TwitterWidgetWidget::validate()
Validate the Twitter block parameters.
File
- src/
Plugin/ Field/ FieldWidget/ TwitterWidgetWidget.php, line 197
Class
- TwitterWidgetWidget
- Plugin implementation of the 'twitter_widget' widget.
Namespace
Drupal\twitter_profile_widget\Plugin\Field\FieldWidgetCode
public function validate($element, FormStateInterface $form_state) {
if (!$this->config
->get('twitter_widget_key')) {
$form_state
->setError($element, $this
->t('Credentials for the Twitter API have not been configured or are invalid. Review the <a href=":widget">Twitter widget</a> settings.', [
':widget' => '/admin/config/media/twitter_profile_widget',
]));
}
$values = $form_state
->getValues();
// Handle parents from Layout Builder.
$fields = isset($values['settings']['block_form']) ? $values['settings']['block_form']['field_twitter_profile_widget'][0] : $values['field_twitter_profile_widget'][0];
if ($fields['list_type'] == 'search' && $fields['search'] == '') {
$form_state
->setError($element['search'], $this
->t('The "Search term" type requires entering a search parameter.'));
}
if ($fields['list_type'] != 'search' && $fields['account'] == '') {
$form_state
->setError($element['account'], $this
->t('This Twitter widget type requires that you enter an account handle.'));
}
if ($fields['list_type'] == 'timeline' && $fields['timeline'] == '') {
$form_state
->setError($element['timeline'], $this
->t('The "User timeline" type requires entering a timeline list.'));
}
}