function linkchecker_form_field_config_form_alter in Link checker 8
Implements hook_form_BASE_FORM_ID_alter().
File
- ./
linkchecker.module, line 72 - This module periodically check links in given node types, blocks etc.
Code
function linkchecker_form_field_config_form_alter(&$form, FormStateInterface $form_state, $form_id) {
/** @var \Drupal\field\FieldConfigInterface $fieldConfig */
$fieldConfig = $form_state
->getFormObject()
->getEntity();
$form['third_party_settings']['linkchecker'] = [
'#type' => 'details',
'#title' => t('Link checker settings'),
];
/** @var \Drupal\linkchecker\Plugin\LinkExtractorManager $linkExtractorManager */
$linkExtractorManager = \Drupal::service('plugin.manager.link_extractor');
$options = [];
foreach ($linkExtractorManager
->getDefinitions() as $definition) {
if (in_array($fieldConfig
->getType(), $definition['field_types'])) {
$options[$definition['id']] = $definition['label'];
}
}
if (empty($options)) {
$form['third_party_settings']['linkchecker']['#description'] = t('This field type is unsupported!');
return;
}
$form['third_party_settings']['linkchecker']['scan'] = [
'#type' => 'checkbox',
'#title' => t('Scan broken links'),
'#default_value' => $fieldConfig
->getThirdPartySetting('linkchecker', 'scan', FALSE),
];
$form['third_party_settings']['linkchecker']['extractor'] = [
'#type' => 'select',
'#title' => t('Extractor'),
'#description' => t('Defines which extractor plugin to use'),
'#empty_value' => '',
'#options' => $options,
'#default_value' => $fieldConfig
->getThirdPartySetting('linkchecker', 'extractor', count($options) === 1 ? key($options) : '_none'),
'#states' => [
'required' => [
':input[name="third_party_settings[linkchecker][scan]"]' => [
'checked' => TRUE,
],
],
'visible' => [
':input[name="third_party_settings[linkchecker][scan]"]' => [
'checked' => TRUE,
],
],
],
];
$form['#entity_builders'][] = 'linkchecker_form_field_config_form_builder';
}