protected function GlobalLinkTranslatorUi::buildContinuousFilter in GlobalLink Connect for Drupal 8
Same name and namespace in other branches
- 8.2 src/GlobalLinkTranslatorUi.php \Drupal\globallink\GlobalLinkTranslatorUi::buildContinuousFilter()
Build the continuous filters.
Parameters
array $form: The form array.
\Drupal\Core\Form\FormStateInterface $form_state: The form state object.
\Drupal\tmgmt\JobInterface $job: The job object.
1 call to GlobalLinkTranslatorUi::buildContinuousFilter()
- GlobalLinkTranslatorUi::checkoutSettingsForm in src/
GlobalLinkTranslatorUi.php - Form callback for the checkout settings form.
File
- src/
GlobalLinkTranslatorUi.php, line 258 - Contains Drupal\globallink\GlobalLinkTranslatorUi.
Class
- GlobalLinkTranslatorUi
- GlobalLink translator UI.
Namespace
Drupal\globallinkCode
protected function buildContinuousFilter(array &$form, FormStateInterface $form_state, JobInterface $job) {
$form['filters_table'] = [
'#type' => 'details',
'#title' => t('Exclusion filters'),
'#open' => TRUE,
'#description' => t('Use exclusion filters to prevent content from being added to the continuous job. The URL allows to use wildcards, use "/blog/*" to exclude all URLs starting with "/blog/", use "*blog*" to exclude all URLs that have blog anywhere in their URL path'),
'#prefix' => '<div id="selected-filters">',
'#suffix' => '</div>',
];
$form['filters_table']['filters'] = [
'#type' => 'table',
'#tree' => TRUE,
'#header' => [
'field' => t('Field'),
'value' => t('Value'),
],
];
// @todo It would probably be better not to save the values without value.
$filters_table = $job
->getSetting('filters_table');
if (!empty($filters_table['filters'])) {
foreach ($filters_table['filters'] as $filter) {
if (!empty($filter['value'])) {
$filters[] = $filter;
}
}
}
else {
$filters = [];
}
if (!$form_state
->has('filters_rows')) {
$form_state
->set('filters_rows', count($filters) + 1);
}
$field_options = [
'url' => t('URL matches'),
'id' => t('ID equals'),
];
for ($i = 0; $i < $form_state
->get('filters_rows'); $i++) {
$filter = isset($filters[$i]) ? $filters[$i] : [];
$filter += [
'field' => '',
'value' => '',
];
$form['filters_table']['filters'][$i] = [
'field' => [
'#type' => 'select',
'#default_value' => $filter['field'],
'#title' => t('Field'),
'#title_display' => 'invisible',
'#options' => $field_options,
],
'value' => [
'#type' => 'textfield',
'#default_value' => $filter['value'],
'#title' => t('Value'),
'#title_display' => 'invisible',
'#size' => 40,
],
];
}
// Select element for available filters.
$form['filters_table']['filter_add_button'] = [
'#type' => 'submit',
'#value' => t('Add another filter'),
'#ajax' => [
'wrapper' => 'selected-filters',
'callback' => [
$this,
'filtersReplace',
],
'method' => 'replace',
],
'#submit' => [
[
$this,
'addfilterSubmit',
],
],
];
}