/** * Builds the backend-specific configuration form. * * @param \Drupal\search_api\ServerInterface $server * The server that is being created or edited. */ public function buildBackendConfigForm(array &$form, FormStateInterface $form_state, ServerInterface $server) { $form['backend_config'] = array('#type' => 'container', '#attributes' => array('id' => 'search-api-backend-config-form'), '#tree' => TRUE); if ($server->hasValidBackend()) { $backend = $server->getBackend(); if ($backend_form = $backend->buildConfigurationForm(array(), $form_state)) { // If the backend plugin changed, notify the user. if (!empty($form_state->getValues()['backend'])) { drupal_set_message($this->t('Please configure the used backend.'), 'warning'); } // Modify the backend plugin configuration container element. $form['backend_config']['#type'] = 'details'; $form['backend_config']['#title'] = $this->t('Configure %plugin backend', array('%plugin' => $backend->label())); $form['backend_config']['#description'] = $backend->getDescription(); $form['backend_config']['#open'] = TRUE; // Attach the backend plugin configuration form. $form['backend_config'] += $backend_form; } } elseif (!$server->isNew()) { drupal_set_message($this->t('The backend plugin is missing or invalid.'), 'error'); } }
/** * Retrieves a list of all config files of a server's Solr backend. * * @param \Drupal\search_api\ServerInterface $server * The Solr server whose files should be retrieved. * @param string $dir_name * (optional) The directory that should be searched for files. Defaults to the * root config directory. * * @return array * An associative array of all config files in the given directory. The keys * are the file names, values are arrays with information about the file. The * files are returned in alphabetical order and breadth-first. * * @throws \Drupal\search_api\SearchApiException * If a problem occurred while retrieving the files. */ public static function getServerFiles(ServerInterface $server, $dir_name = NULL) { $response = $server->getBackend()->getFile($dir_name); // Search for directories and recursively merge directory files. $files_data = json_decode($response->getBody(), TRUE); $files_list = $files_data['files']; $dir_length = strlen($dir_name) + 1; $result = array('' => array()); foreach ($files_list as $file_name => $file_info) { // Annoyingly, Solr 4.7 changed the way the admin/file handler returns // the file names when listing directory contents: the returned name is now // only the base name, not the complete path from the config root directory. // We therefore have to check for this case. if ($dir_name && substr($file_name, 0, $dir_length) !== "{$dir_name}/") { $file_name = "{$dir_name}/" . $file_name; } if (empty($file_info['directory'])) { $result[''][$file_name] = $file_info; } else { $result[$file_name] = static::getServerFiles($server, $file_name); } } ksort($result); ksort($result['']); return array_reduce($result, 'array_merge', array()); }