/**
  * {@inheritdoc}
  */
 public function submitConfigurationForm(array &$form, FormStateInterface $form_state)
 {
     $values = $form_state->getValues();
     $values['default'] = (bool) $values['default'];
     $values['roles'] = array_values(array_filter($values['roles']));
     $form_state->set('values', $values);
     parent::submitConfigurationForm($form, $form_state);
 }
Exemple #2
0
  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form = parent::buildConfigurationForm($form, $form_state);

    $form['#attached']['library'][] = 'search_api/drupal.search_api.admin_css';
    $form['description'] = array(
      '#markup' => $this->t('This data alteration lets you define additional fields that will be added to this index. Each of these new fields will be an aggregation of one or more existing fields.<br />To add a new aggregated field, click the "Add new field" button and then fill out the form.<br />To remove a previously defined field, click the "Remove field" button.<br />You can also change the names or contained fields of existing aggregated fields.'),
    );

    $this->buildFieldsForm($form, $form_state);

    $form['actions']['#type'] = 'actions';
    $form['actions'] = array(
      '#type' => 'actions',
      'add' => array(
        '#type' => 'submit',
        '#value' => $this->t('Add new Field'),
        '#submit' => array(array($this, 'submitAjaxFieldButton')),
        '#limit_validation_errors' => array(),
        '#name' => 'add_aggregation_field',
        '#ajax' => array(
          'callback' => array($this, 'buildAjaxAddFieldButton'),
          'wrapper' => 'search-api-alter-add-aggregation-field-settings',
        ),
      ),
    );

    return $form;
  }
 /**
  * {@inheritdoc}
  */
 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition)
 {
     /** @var static $processor */
     $processor = parent::create($container, $configuration, $plugin_id, $plugin_definition);
     /** @var \Drupal\Core\Logger\LoggerChannelInterface $logger */
     $logger = $container->get('logger.factory')->get('search_api');
     $processor->setLogger($logger);
     return $processor;
 }
 /**
  * {@inheritdoc}
  */
 public function validateConfigurationForm(array &$form, FormStateInterface $form_state)
 {
     parent::validateConfigurationForm($form, $form_state);
     $fields = array_filter($form_state->getValues()['fields']);
     if ($fields) {
         $fields = array_keys($fields);
     }
     $form_state->setValue('fields', $fields);
 }
Exemple #5
0
 /**
  * {@inheritdoc}
  */
 public function buildConfigurationForm(array $form, FormStateInterface $form_state)
 {
     $form = parent::buildConfigurationForm($form, $form_state);
     $form['highlight'] = array('#type' => 'select', '#title' => $this->t('Highlight returned field data'), '#description' => $this->t('Select whether returned fields should be highlighted.'), '#options' => array('always' => $this->t('Always'), 'server' => $this->t('If the server returns fields'), 'never' => $this->t('Never')), '#default_value' => $this->configuration['highlight']);
     $form['excerpt'] = array('#type' => 'checkbox', '#title' => $this->t('Create excerpt'), '#description' => $this->t('When enabled, an excerpt will be created for searches with keywords, containing all occurrences of keywords in a fulltext field.'), '#default_value' => $this->configuration['excerpt']);
     $form['excerpt_length'] = array('#type' => 'number', '#title' => $this->t('Excerpt length'), '#description' => $this->t('The requested length of the excerpt, in characters'), '#default_value' => $this->configuration['excerpt_length'], '#min' => 50, '#states' => array('visible' => array('#edit-processors-search-api-highlighting-settings-excerpt' => array('checked' => TRUE))));
     $form['prefix'] = array('#type' => 'textfield', '#title' => $this->t('Highlighting prefix'), '#description' => $this->t('Text/HTML that will be prepended to all occurrences of search keywords in highlighted text'), '#default_value' => $this->configuration['prefix']);
     $form['suffix'] = array('#type' => 'textfield', '#title' => $this->t('Highlighting suffix'), '#description' => $this->t('Text/HTML that will be appended to all occurrences of search keywords in highlighted text'), '#default_value' => $this->configuration['suffix']);
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function submitConfigurationForm(array &$form, FormStateInterface $form_state)
 {
     $values = $form_state->getValues();
     // Remove the unnecessary form_state values, so no overhead is stored.
     unset($values['actions']);
     if (!empty($values['fields'])) {
         foreach ($values['fields'] as &$field_definition) {
             unset($field_definition['type_descriptions'], $field_definition['actions']);
             $field_definition['fields'] = array_values(array_filter($field_definition['fields']));
         }
     } else {
         $values['fields'] = array();
     }
     $form_state->setValues($values);
     parent::submitConfigurationForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function calculateDependencies()
 {
     parent::calculateDependencies();
     $view_modes = $this->configuration['view_mode'];
     foreach ($this->index->getDatasources() as $datasource_id => $datasource) {
         if ($entity_type_id = $datasource->getEntityTypeId() && !empty($view_modes[$datasource_id])) {
             foreach ($view_modes[$datasource_id] as $view_mode) {
                 if ($view_mode) {
                     /** @var \Drupal\Core\Entity\EntityViewModeInterface $view_mode_entity */
                     $view_mode_entity = EntityViewMode::load($entity_type_id . '.' . $view_mode);
                     if ($view_mode_entity) {
                         $this->addDependency($view_mode_entity->getConfigDependencyKey(), $view_mode_entity->getConfigDependencyName());
                     }
                 }
             }
         }
     }
     return $this->dependencies;
 }
 /**
  * {@inheritdoc}
  */
 public function buildConfigurationForm(array $form, FormStateInterface $form_state)
 {
     $form = parent::buildConfigurationForm($form, $form_state);
     $roles = user_role_names();
     $form['roles'] = array('#type' => 'select', '#title' => $this->t('User roles'), '#description' => $this->t('Your item will be rendered as seen by a user with the selected roles. We recommend to just use "@anonymous" here to prevent data leaking out to unauthorized roles.', array('@anonymous' => $roles[AccountInterface::ANONYMOUS_ROLE])), '#options' => $roles, '#multiple' => TRUE, '#default_value' => $this->configuration['roles'], '#required' => TRUE);
     $form['view_mode'] = array('#type' => 'item', '#description' => $this->t('You can choose the view modes to use for rendering the items of different datasources and bundles. We recommend using a dedicated view mode (e.g., the "Search index" view mode available by default for content) to make sure that only relevant data (especially no field labels) will be included in the index.'));
     $options_present = FALSE;
     foreach ($this->index->getDatasources() as $datasource_id => $datasource) {
         $bundles = $datasource->getBundles();
         foreach ($bundles as $bundle_id => $bundle_label) {
             $view_modes = $datasource->getViewModes($bundle_id);
             if (count($view_modes) > 1) {
                 $form['view_mode'][$datasource_id][$bundle_id] = array('#type' => 'select', '#title' => $this->t('View mode for %datasource » %bundle', array('%datasource' => $datasource->label(), '%bundle' => $bundle_label)), '#options' => $view_modes);
                 if (isset($this->configuration['view_mode'][$datasource_id][$bundle_id])) {
                     $form['view_mode'][$datasource_id][$bundle_id]['#default_value'] = $this->configuration['view_mode'][$datasource_id][$bundle_id];
                 }
                 $options_present = TRUE;
             } elseif ($view_modes) {
                 $form['view_mode'][$datasource_id][$bundle_id] = array('#type' => 'value', '#value' => key($view_modes));
             }
         }
     }
     // If there are no datasources/bundles with more than one view mode, don't
     // display the description either.
     if (!$options_present) {
         unset($form['view_mode']['#type']);
         unset($form['view_mode']['#description']);
     }
     return $form;
 }