Example #1
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     parent::submitForm($form, $form_state);
     /** @var $index \Drupal\search_api\IndexInterface */
     $index = $this->getEntity();
     $index->setOptions($form_state->getValue('options', array()) + $this->originalEntity->getOptions());
     $datasources = $form_state->getValue('datasources', array());
     /** @var \Drupal\search_api\Datasource\DatasourceInterface[] $datasource_plugins */
     $datasource_plugins = $this->originalEntity->getDatasources(FALSE);
     $datasource_settings = array();
     foreach ($datasources as $datasource_id) {
         $datasource = $datasource_plugins[$datasource_id];
         $datasource_form = !empty($form['datasource_configs'][$datasource_id]) ? $form['datasource_configs'][$datasource_id] : array();
         $datasource_form_state = new SubFormState($form_state, array('datasource_configs', $datasource_id));
         $datasource->submitConfigurationForm($datasource_form, $datasource_form_state);
         $datasource_settings[$datasource_id] = $datasource;
     }
     $index->setDatasources($datasource_settings);
     // Call submitConfigurationForm() for the (possibly new) tracker.
     // @todo It seems if we change the tracker, we would validate/submit the old
     //   tracker's form using the new tracker. Shouldn't be done, of course.
     //   Similar above for datasources, though there of course the values will
     //   just always be empty (because datasources have their plugin ID in the
     //   form structure).
     $tracker_id = $form_state->getValue('tracker', NULL);
     if ($this->originalEntity->getTrackerId() == $tracker_id) {
         $tracker = $this->originalEntity->getTrackerInstance();
     } else {
         $tracker = $this->trackerPluginManager->createInstance($tracker_id, array('index' => $this->originalEntity));
     }
     $tracker_form_state = new SubFormState($form_state, array('tracker_config'));
     $tracker->submitConfigurationForm($form['tracker_config'], $tracker_form_state);
     $index->setTracker($tracker);
 }
Example #2
0
  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    parent::submitForm($form, $form_state);

    /** @var $index \Drupal\search_api\IndexInterface */
    $index = $this->getEntity();
    $index->setOptions($form_state->getValue('options', array()) + $this->originalEntity->getOptions());

    $datasources = $form_state->getValue('datasources', array());
    /** @var \Drupal\search_api\Datasource\DatasourceInterface[] $datasource_plugins */
    $datasource_plugins = $this->originalEntity->getDatasources(FALSE);
    $datasource_configuration = array();
    foreach ($datasources as $datasource_id) {
      $datasource = $datasource_plugins[$datasource_id];
      $datasource_form = (!empty($form['datasource_configs'][$datasource_id])) ? $form['datasource_configs'][$datasource_id] : array();
      $datasource_form_state = new SubFormState($form_state, array('datasource_configs', $datasource_id));
      $datasource->submitConfigurationForm($datasource_form, $datasource_form_state);
      $datasource_configuration[$datasource_id] = $datasource->getConfiguration();
    }
    $index->set('datasource_configs', $datasource_configuration);

    // Call submitConfigurationForm() for the (possibly new) tracker.
    // @todo It seems if we change the tracker, we would validate/submit the old
    //   tracker's form using the new tracker. Shouldn't be done, of course.
    //   Similar above for datasources, though there of course the values will
    //   just always be empty (because datasources have their plugin ID in the
    //   form structure).
    $tracker_id = $form_state->getValue('tracker', NULL);
    if ($this->originalEntity->getTrackerId() == $tracker_id) {
      $tracker = $this->originalEntity->getTracker();
    }
    else {
      $tracker = $this->trackerPluginManager->createInstance($tracker_id, array('index' => $this->originalEntity));
    }

    $tracker_form_state = new SubFormState($form_state, array('tracker_config'));
    $tracker->submitConfigurationForm($form['tracker_config'], $tracker_form_state);
    $index->set('tracker_config', $tracker->getConfiguration());

    // Invalidate caches, so this gets picked up by the views wizard.
    Cache::invalidateTags(array('views_data'));
    // Remove this line when https://www.drupal.org/node/2370365 gets fixed.
    Cache::invalidateTags(array('extension:views'));
  }