/** * Builds the form for the basic server properties. * * @param \Drupal\search_api\ServerInterface $server * The server that is being created or edited. */ public function buildEntityForm(array &$form, FormStateInterface $form_state, ServerInterface $server) { $form['#attached']['library'][] = 'search_api/drupal.search_api.admin_css'; $form['name'] = array('#type' => 'textfield', '#title' => $this->t('Server name'), '#description' => $this->t('Enter the displayed name for the server.'), '#default_value' => $server->label(), '#required' => TRUE); $form['id'] = array('#type' => 'machine_name', '#default_value' => $server->id(), '#maxlength' => 50, '#required' => TRUE, '#machine_name' => array('exists' => array($this->getStorage(), 'load'), 'source' => array('name')), '#disabled' => !$server->isNew()); $form['status'] = array('#type' => 'checkbox', '#title' => $this->t('Enabled'), '#description' => $this->t('Only enabled servers can index items or execute searches.'), '#default_value' => $server->status()); $form['description'] = array('#type' => 'textarea', '#title' => $this->t('Description'), '#description' => $this->t('Enter a description for the server.'), '#default_value' => $server->getDescription()); $backend_options = $this->getBackendOptions(); if ($backend_options) { if (count($backend_options) == 1) { $server->set('backend', key($backend_options)); } $form['backend'] = array('#type' => 'radios', '#title' => $this->t('Backend'), '#description' => $this->t('Choose a backend to use for this server.'), '#options' => $backend_options, '#default_value' => $server->getBackendId(), '#required' => TRUE, '#ajax' => array('callback' => array(get_class($this), 'buildAjaxBackendConfigForm'), 'wrapper' => 'search-api-backend-config-form', 'method' => 'replace', 'effect' => 'fade')); } else { drupal_set_message($this->t('There are no backend plugins available for the Search API. Please install a <a href=":url">module that provides a backend plugin</a> to proceed.', array(':url' => Url::fromUri('https://www.drupal.org/node/1254698')->toString())), 'error'); $form = array(); } }
/** * Tests whether updating a server works correctly. * * @param \Drupal\search_api\ServerInterface $server * The server used for this test. */ public function serverUpdate(ServerInterface $server) { $server->set('name', $server->label() . ' - edited'); $server->save(); $key = 'search_api_test_backend.methods_called.' . $server->id(); $methods_called = \Drupal::state()->get($key, array()); $this->assertContains('preUpdate', $methods_called, 'Backend::preUpdate() called for update.'); $this->assertContains('postUpdate', $methods_called, 'Backend::postUpdate() called for update.'); $this->serverLoad($server); }