Created
September 23, 2015 10:58
-
-
Save nickveenhof/aa99d64d95493f1387fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/config/schema/search_api.index.schema.yml b/config/schema/search_api.index.schema.yml | |
index 96a0abb..7cbced6 100644 | |
--- a/config/schema/search_api.index.schema.yml | |
+++ b/config/schema/search_api.index.schema.yml | |
@@ -34,6 +34,9 @@ search_api.index.*: | |
boost: | |
type: float | |
label: 'Boost' | |
+ faceted: | |
+ type: boolean | |
+ label: 'Faceted' | |
additional fields: | |
type: sequence | |
label: 'Included additional fields' | |
diff --git a/search_api.links.task.yml b/search_api.links.task.yml | |
index 8eb808c..8ea2898 100644 | |
--- a/search_api.links.task.yml | |
+++ b/search_api.links.task.yml | |
@@ -25,3 +25,8 @@ entity.search_api_index.processors: | |
base_route: entity.search_api_index.canonical | |
title: 'Processors' | |
weight: 20 | |
+entity.search_api_index.facets: | |
+ route_name: entity.search_api_index.facets | |
+ base_route: entity.search_api_index.canonical | |
+ title: 'Facets' | |
+ weight: 20 | |
diff --git a/search_api.routing.yml b/search_api.routing.yml | |
index 195fb28..9bea273 100644 | |
--- a/search_api.routing.yml | |
+++ b/search_api.routing.yml | |
@@ -109,6 +109,13 @@ entity.search_api_index.fields: | |
requirements: | |
_entity_access: 'search_api_index.fields' | |
+entity.search_api_index.facets: | |
+ path: '/admin/config/search/search-api/index/{search_api_index}/facets' | |
+ defaults: | |
+ _entity_form: 'search_api_index.facets' | |
+ requirements: | |
+ _entity_access: 'search_api_index.facets' | |
+ | |
entity.search_api_index.processors: | |
path: '/admin/config/search/search-api/index/{search_api_index}/processors' | |
defaults: | |
diff --git a/search_api.theme.inc b/search_api.theme.inc | |
index 080aa02..5131fef 100644 | |
--- a/search_api.theme.inc | |
+++ b/search_api.theme.inc | |
@@ -24,7 +24,7 @@ use Drupal\search_api\Utility; | |
*/ | |
function theme_search_api_admin_fields_table($variables) { | |
$form = $variables['element']; | |
- $header = array(t('Field'), t('Machine name'), t('Indexed'), t('Type'), t('Boost')); | |
+ $header = array(t('Field'), t('Machine name'), t('Indexed'), t('Type'), t('Boost'), t('Facet')); | |
$rows = array(); | |
if (!empty($form['fields'])) { | |
@@ -303,7 +303,10 @@ function theme_search_api_index($variables) { | |
$vars = array('@url' => Url::fromUri('https://drupal.org/node/2009804#server-index-status')->toString()); | |
// Build the server index status info. | |
$label = t('Server index status'); | |
- $info = \Drupal::translation()->formatPlural($response->getResultCount(), 'There is 1 item indexed on the server for this index. (<a href="@url">More information</a>)', 'There are @count items indexed on the server for this index. (<a href="@url">More information</a>)', $vars); | |
+ $info = ""; | |
+ if (!empty($response)) { | |
+ $info = \Drupal::translation()->formatPlural($response->getResultCount(), 'There is 1 item indexed on the server for this index. (<a href="@url">More information</a>)', 'There are @count items indexed on the server for this index. (<a href="@url">More information</a>)', $vars); | |
+ } | |
$rows[] = Utility::deepCopy($row); | |
} | |
diff --git a/src/Entity/Index.php b/src/Entity/Index.php | |
index 8a34290..7ce460b 100644 | |
--- a/src/Entity/Index.php | |
+++ b/src/Entity/Index.php | |
@@ -41,6 +41,7 @@ use Drupal\views\Views; | |
* "edit" = "Drupal\search_api\Form\IndexForm", | |
* "fields" = "Drupal\search_api\Form\IndexFieldsForm", | |
* "processors" = "Drupal\search_api\Form\IndexProcessorsForm", | |
+ * "facets" = "Drupal\search_api\Form\IndexFacetsForm", | |
* "delete" = "Drupal\search_api\Form\IndexDeleteConfirmForm", | |
* "disable" = "Drupal\search_api\Form\IndexDisableConfirmForm", | |
* "reindex" = "Drupal\search_api\Form\IndexReindexConfirmForm", | |
@@ -817,9 +818,14 @@ class Index extends ConfigEntityBase implements IndexInterface { | |
$field->setIndexed(TRUE); | |
if (isset($field_options[$key])) { | |
$field->setType($field_options[$key]['type']); | |
+ | |
if (isset($field_options[$key]['boost'])) { | |
$field->setBoost($field_options[$key]['boost']); | |
} | |
+ | |
+ if (isset($field_options[$key]['faceted'])) { | |
+ $field->setFaceted($field_options[$key]['faceted']); | |
+ } | |
} | |
$this->fields[1]['fields'][$key] = $field; | |
} | |
diff --git a/src/Form/IndexFacetsForm.php b/src/Form/IndexFacetsForm.php | |
index efa30b5..bcc2cba 100644 | |
--- a/src/Form/IndexFacetsForm.php | |
+++ b/src/Form/IndexFacetsForm.php | |
@@ -2,24 +2,20 @@ | |
/** | |
* @file | |
- * Contains \Drupal\search_api\Form\IndexProcessorsForm. | |
+ * Contains \Drupal\search_api\Form\IndexFacetsForm. | |
*/ | |
namespace Drupal\search_api\Form; | |
-use Drupal\Component\Utility\Html; | |
-use Drupal\Component\Utility\SafeMarkup; | |
use Drupal\Core\Entity\EntityForm; | |
use Drupal\Core\Entity\EntityManagerInterface; | |
use Drupal\Core\Form\FormStateInterface; | |
-use Drupal\search_api\Processor\ProcessorInterface; | |
-use Drupal\search_api\Processor\ProcessorPluginManager; | |
use Symfony\Component\DependencyInjection\ContainerInterface; | |
/** | |
* Provides a form for configuring the processors of a search index. | |
*/ | |
-class IndexProcessorsForm extends EntityForm { | |
+class IndexFacetsForm extends EntityForm { | |
/** | |
* The index being configured. | |
@@ -36,23 +32,15 @@ class IndexProcessorsForm extends EntityForm { | |
protected $entityManager; | |
/** | |
- * The datasource manager. | |
- * | |
- * @var \Drupal\search_api\Processor\ProcessorPluginManager | |
- */ | |
- protected $processorPluginManager; | |
- | |
- /** | |
- * Constructs an IndexProcessorsForm object. | |
+ * Constructs an IndexFacetsForm object. | |
* | |
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager | |
* The entity manager. | |
- * @param \Drupal\search_api\Processor\ProcessorPluginManager $processor_plugin_manager | |
- * The processor plugin manager. | |
*/ | |
- public function __construct(EntityManagerInterface $entity_manager, ProcessorPluginManager $processor_plugin_manager) { | |
+ public function __construct(EntityManagerInterface $entity_manager, \Drupal\facet_api\Adapter\AdapterPluginManager $adapter_manager, \Drupal\facet_api\Searcher\SearcherPluginManager $searcher_manager) { | |
$this->entityManager = $entity_manager; | |
- $this->processorPluginManager = $processor_plugin_manager; | |
+ $this->adapterManager = $adapter_manager; | |
+ $this->searcherManager = $searcher_manager; | |
} | |
/** | |
@@ -61,9 +49,11 @@ class IndexProcessorsForm extends EntityForm { | |
public static function create(ContainerInterface $container) { | |
/** @var \Drupal\Core\Entity\EntityManagerInterface $entity_manager */ | |
$entity_manager = $container->get('entity.manager'); | |
- /** @var \Drupal\search_api\Processor\ProcessorPluginManager $processor_plugin_manager */ | |
- $processor_plugin_manager = $container->get('plugin.manager.search_api.processor'); | |
- return new static($entity_manager, $processor_plugin_manager); | |
+ /** @var \Drupal\facet_api\AdapterManager $adapter_manager */ | |
+ $adapter_manager = $container->get('plugin.manager.facet_api.adapter'); | |
+ /** @var \Drupal\facet_api\Searcher\SearcherPluginManager $searcher_manager */ | |
+ $searcher_manager = $container->get('plugin.manager.facet_api.searcher'); | |
+ return new static($entity_manager, $adapter_manager, $searcher_manager); | |
} | |
/** | |
@@ -77,216 +67,159 @@ class IndexProcessorsForm extends EntityForm { | |
* {@inheritdoc} | |
*/ | |
public function form(array $form, FormStateInterface $form_state) { | |
- $form['#attached']['library'][] = 'search_api/drupal.search_api.admin_css'; | |
- | |
- // Retrieve lists of all processors, and the stages and weights they have. | |
- if (!$form_state->has('processors')) { | |
- $all_processors = $this->entity->getProcessors(FALSE); | |
- $sort_processors = function (ProcessorInterface $a, ProcessorInterface $b) { | |
- return strnatcasecmp($a->label(), $b->label()); | |
- }; | |
- uasort($all_processors, $sort_processors); | |
+ $index = $this->entity; | |
+ if (!$index->isServerEnabled()) { | |
+ return array('#markup' => t('Since this index is at the moment disabled, no facets can be activated.')); | |
} | |
- else { | |
- $all_processors = $form_state->get('processors'); | |
+ if (!$index->getServer()->supportsFeature('search_api_facets')) { | |
+ return array('#markup' => t('This index uses a server that does not support facet functionality.')); | |
} | |
- $stages = $this->processorPluginManager->getProcessingStages(); | |
- $processors_by_stage = array(); | |
- foreach ($stages as $stage => $definition) { | |
- $processors_by_stage[$stage] = $this->entity->getProcessorsByStage($stage, FALSE); | |
- } | |
+ // Instantiates adapter, loads realm. | |
+ $adapter = $this->adapterManager->getDefinition('search_api'); | |
- $processor_settings = $this->entity->getOption('processors'); | |
+ // @todo inject realmManager to load realms. Look at the DataSourceDerivative | |
+ $realm_name = $index->getServerId() . ':' . $index->id(); | |
- $form['#tree'] = TRUE; | |
- $form['#attached']['library'][] = 'search_api/drupal.search_api.index-active-formatters'; | |
- $form['#title'] = $this->t('Manage processors for search index %label', array('%label' => $this->entity->label())); | |
- $form['description']['#markup'] = '<p>' . $this->t('Configure processors which will pre- and post-process data at index and search time.') . '</p>'; | |
+ $realm = $this->searcherManager->getInstance(); | |
+ /*$realm = facetapi_realm_load($realm_name); | |
+ // @todo inject facetManager to get Facet Info from Searchers | |
+ $facet_info = facetapi_get_facet_info($searcher); | |
- // Add the list of processors with checkboxes to enable/disable them. | |
- $form['status'] = array( | |
- '#type' => 'fieldset', | |
- '#title' => $this->t('Enabled'), | |
- '#attributes' => array('class' => array( | |
- 'search-api-status-wrapper', | |
- )), | |
+ $form['#facetapi'] = array( | |
+ 'adapter' => $adapter, | |
+ 'realm' => $realm, | |
+ 'facet_info' => $facet_info | |
); | |
- foreach ($all_processors as $processor_id => $processor) { | |
- $clean_css_id = Html::cleanCssIdentifier($processor_id); | |
- $form['status'][$processor_id] = array( | |
- '#type' => 'checkbox', | |
- '#title' => $processor->label(), | |
- '#default_value' => $processor->isLocked() || !empty($processor_settings[$processor_id]), | |
- '#description' => $processor->getDescription(), | |
- '#attributes' => array( | |
- 'class' => array( | |
- 'search-api-processor-status-' . $clean_css_id, | |
- ), | |
- 'data-id' => $clean_css_id, | |
- ), | |
- '#disabled' => $processor->isLocked(), | |
- '#access' => !$processor->isHidden(), | |
- ); | |
- } | |
- $form['weights'] = array( | |
- '#type' => 'fieldset', | |
- '#title' => t('Processor order'), | |
+ $form['description'] = array( | |
+ '#prefix' => '<div class="facetapi-realm-description">', | |
+ '#markup' => filter_xss_admin($realm['description']), | |
+ '#suffix' => "</div>\n", | |
); | |
- // Order enabled processors per stage. | |
- foreach ($stages as $stage => $description) { | |
- $form['weights'][$stage] = array ( | |
- '#type' => 'fieldset', | |
- '#title' => $description['label'], | |
- '#attributes' => array('class' => array( | |
- 'search-api-stage-wrapper', | |
- 'search-api-stage-wrapper-' . Html::cleanCssIdentifier($stage), | |
- )), | |
- ); | |
- $form['weights'][$stage]['order'] = array( | |
- '#type' => 'table', | |
- ); | |
- $form['weights'][$stage]['order']['#tabledrag'][] = array( | |
- 'action' => 'order', | |
- 'relationship' => 'sibling', | |
- 'group' => 'search-api-processor-weight-' . Html::cleanCssIdentifier($stage), | |
+ | |
+ $form['performance'] = array( | |
+ '#prefix' => '<div class="facetapi-performance-note">', | |
+ '#markup' => t('For performance reasons, you should only enable facets that you intend to have available to users on the search page.'), | |
+ '#suffix' => "</div>\n", | |
+ ); | |
+ | |
+ $form['table'] = array( | |
+ '#theme' => 'facetapi_realm_settings_table', | |
+ '#facetapi' => &$form['#facetapi'], | |
+ 'operations' => array('#tree' => TRUE), | |
+ 'weight' => array('#tree' => TRUE), | |
+ ); | |
+ | |
+ // Builds "enabled_facets" options. | |
+ $options = $default_value = array(); | |
+ foreach ($form['#facetapi']['facet_info'] as $facet_name => $facet) { | |
+ $settings = $adapter->getFacetSettings($facet, $realm); | |
+ $global_settings = $adapter->getFacetSettingsGlobal($facet); | |
+ | |
+ // Builds array of operations to use in the dropbutton. | |
+ $operations = array(); | |
+ $operations[] = array( | |
+ 'title' => t('Configure display'), | |
+ 'href' => facetapi_get_settings_path($searcher, $realm['name'], $facet_name, 'edit') | |
); | |
- } | |
- foreach ($processors_by_stage as $stage => $processors) { | |
- /** @var \Drupal\search_api\Processor\ProcessorInterface $processor */ | |
- foreach ($processors as $processor_id => $processor) { | |
- $weight = isset($processor_settings[$processor_id]['weights'][$stage]) | |
- ? $processor_settings[$processor_id]['weights'][$stage] | |
- : $processor->getDefaultWeight($stage); | |
- if ($processor->isHidden()) { | |
- $form['processors'][$processor_id]['weights'][$stage] = array( | |
- '#type' => 'value', | |
- '#value' => $weight, | |
- ); | |
- continue; | |
- } | |
- $form['weights'][$stage]['order'][$processor_id]['#attributes']['class'][] = 'draggable'; | |
- $form['weights'][$stage]['order'][$processor_id]['#attributes']['class'][] = 'search-api-processor-weight--' . Html::cleanCssIdentifier($processor_id); | |
- $form['weights'][$stage]['order'][$processor_id]['#weight'] = $weight; | |
- $form['weights'][$stage]['order'][$processor_id]['label'] = array( | |
- '#markup' => SafeMarkup::checkPlain($processor->label()), | |
+ if ($facet['dependency plugins']) { | |
+ $operations[] = array( | |
+ 'title' => t('Configure dependencies'), | |
+ 'href' => facetapi_get_settings_path($searcher, $realm['name'], $facet_name, 'dependencies') | |
); | |
- $form['weights'][$stage]['order'][$processor_id]['weight'] = array( | |
- '#type' => 'weight', | |
- '#title' => $this->t('Weight for processor %title', array('%title' => $processor->label())), | |
- '#title_display' => 'invisible', | |
- '#default_value' => $weight, | |
- '#parents' => array('processors', $processor_id, 'weights', $stage), | |
- '#attributes' => array('class' => array( | |
- 'search-api-processor-weight-' . Html::cleanCssIdentifier($stage), | |
- )), | |
+ } | |
+ if (facetapi_filters_load($facet_name, $searcher, $realm['name'])) { | |
+ $operations[] = array( | |
+ 'title' => t('Configure filters'), | |
+ 'href' => facetapi_get_settings_path($searcher, $realm['name'], $facet_name, 'filters') | |
); | |
} | |
- } | |
- | |
- // Add vertical tabs containing the settings for the processors. Tabs for | |
- // disabled processors are hidden with JS magic, but need to be included in | |
- // case the processor is enabled. | |
- $form['processor_settings'] = array( | |
- '#title' => $this->t('Processor settings'), | |
- '#type' => 'vertical_tabs', | |
- ); | |
- | |
- foreach ($all_processors as $processor_id => $processor) { | |
- $processor_form_state = new SubFormState($form_state, array('processors', $processor_id, 'settings')); | |
- $processor_form = $processor->buildConfigurationForm($form, $processor_form_state); | |
- if ($processor_form) { | |
- $form['settings'][$processor_id] = array( | |
- '#type' => 'details', | |
- '#title' => $processor->label(), | |
- '#group' => 'processor_settings', | |
- '#parents' => array('processors', $processor_id, 'settings'), | |
- '#attributes' => array('class' => array( | |
- 'search-api-processor-settings-' . Html::cleanCssIdentifier($processor_id), | |
- )), | |
+ $operations[] = array( | |
+ 'title' => t('Export configuration'), | |
+ 'href' => facetapi_get_settings_path($searcher, $realm['name'], $facet_name, 'export') | |
+ ); | |
+ if (facetapi_is_overridden($settings) || facetapi_is_overridden($global_settings)) { | |
+ $operations[] = array( | |
+ 'title' => t('Revert configuration'), | |
+ 'href' => facetapi_get_settings_path($searcher, $realm['name'], $facet_name, 'revert') | |
); | |
- $form['settings'][$processor_id] += $processor_form; | |
} | |
- } | |
- return $form; | |
- } | |
+ $form['table']['operations'][$facet_name] = array( | |
+ '#theme' => 'links__ctools_dropbutton', | |
+ '#links' => $operations, | |
+ '#attributes' => array( | |
+ 'class' => array('inline', 'links', 'actions', 'horizontal', 'right') | |
+ ), | |
+ ); | |
- /** | |
- * {@inheritdoc} | |
- */ | |
- public function validateForm(array &$form, FormStateInterface $form_state) { | |
- parent::validateForm($form, $form_state); | |
- | |
- $values = $form_state->getValues(); | |
- /** @var \Drupal\search_api\Processor\ProcessorInterface[] $processors */ | |
- $processors = $this->entity->getProcessors(FALSE); | |
- | |
- // Iterate over all processors that have a form and are enabled. | |
- foreach ($form['settings'] as $processor_id => $processor_form) { | |
- if (!empty($values['status'][$processor_id])) { | |
- $processor_form_state = new SubFormState($form_state, array('processors', $processor_id, 'settings')); | |
- $processors[$processor_id]->validateConfigurationForm($form['settings'][$processor_id], $processor_form_state); | |
- } | |
- } | |
- } | |
+ // Adds weight if sortable. | |
+ if ($realm['sortable']) { | |
- /** | |
- * {@inheritdoc} | |
- */ | |
- public function submitForm(array &$form, FormStateInterface $form_state) { | |
- $values = $form_state->getValues(); | |
- $new_settings = array(); | |
- | |
- // Store processor settings. | |
- // @todo Go through all available processors, enable/disable with method on | |
- // processor plugin to allow reaction. | |
- /** @var \Drupal\search_api\Processor\ProcessorInterface $processor */ | |
- $processors = $this->entity->getProcessors(FALSE); | |
- foreach ($processors as $processor_id => $processor) { | |
- if (empty($values['status'][$processor_id])) { | |
- continue; | |
- } | |
- $new_settings[$processor_id] = array( | |
- 'processor_id' => $processor_id, | |
- 'weights' => array(), | |
- 'settings' => array(), | |
- ); | |
- $processor_values = $values['processors'][$processor_id]; | |
- if (!empty($processor_values['weights'])) { | |
- $new_settings[$processor_id]['weights'] = $processor_values['weights']; | |
- } | |
- if (isset($form['settings'][$processor_id])) { | |
- $processor_form_state = new SubFormState($form_state, array('processors', $processor_id, 'settings')); | |
- $processor->submitConfigurationForm($form['settings'][$processor_id], $processor_form_state); | |
- $new_settings[$processor_id]['settings'] = $processor->getConfiguration(); | |
+ $form['#facetapi']['facet_info'][$facet_name]['weight'] = $settings->settings['weight']; | |
+ $form['table']['weight'][$facet_name] = array( | |
+ '#type' => 'select', | |
+ '#title' => t('Weight for @title', array('@title' => $facet['label'])), | |
+ '#title_display' => 'invisible', | |
+ '#options' => drupal_map_assoc(range(-50, 50)), | |
+ '#default_value' => $settings->settings['weight'], | |
+ '#attributes' => array('class' => array('facetapi-facet-weight')), | |
+ ); | |
} | |
+ | |
+ $options[$facet_name] = ''; | |
+ $default_value[$facet_name] = (!$settings->enabled) ? 0 : $facet_name; | |
} | |
- // Sort the processors so we won't have unnecessary changes. | |
- ksort($new_settings); | |
- if (!$this->entity->getOption('processors', array()) !== $new_settings) { | |
- $this->entity->setOption('processors', $new_settings); | |
- $this->entity->save(); | |
- $this->entity->reindex(); | |
- drupal_set_message($this->t('The indexing workflow was successfully edited. All content was scheduled for reindexing so the new settings can take effect.')); | |
+ // Sorts by the weight appended above. | |
+ uasort($form['#facetapi']['facet_info'], 'drupal_sort_weight'); | |
+ | |
+ $form['table']['enabled_facets'] = array( | |
+ '#type' => 'checkboxes', | |
+ '#options' => $options, | |
+ '#default_value' => $default_value, | |
+ ); | |
+ | |
+ // Checks whether block caching is enabled, sets description accordingly. | |
+ if (!$disabled = (module_implements('node_grants') || !variable_get('block_cache', FALSE))) { | |
+ $description = t('Configure the appropriate cache setting for facet blocks.'); | |
} | |
else { | |
- drupal_set_message($this->t('No values were changed.')); | |
+ $description = t( | |
+ 'To enable block caching, visit the <a href="@performance-page">performance page</a>.', | |
+ array('@performance-page' => url('admin/config/development/performance', array('query' => array('destination' => current_path())))) | |
+ ); | |
} | |
- } | |
+ $form['block_cache'] = array( | |
+ '#type' => 'select', | |
+ '#access' => ('block' == $realm_name), | |
+ '#title' => t('Block cache settings'), | |
+ '#disabled' => $disabled, | |
+ '#options' => array( | |
+ DRUPAL_NO_CACHE => t('Do not cache'), | |
+ DRUPAL_CACHE_PER_ROLE | DRUPAL_CACHE_PER_PAGE => t('Per role'), | |
+ DRUPAL_CACHE_PER_USER | DRUPAL_CACHE_PER_PAGE => t('Per user'), | |
+ ), | |
+ '#default_value' => variable_get('facetapi:block_cache:' . $searcher, DRUPAL_NO_CACHE), | |
+ '#description' => $description, | |
+ ); | |
- /** | |
- * {@inheritdoc} | |
- */ | |
- protected function actions(array $form, FormStateInterface $form_state) { | |
- $actions = parent::actions($form, $form_state); | |
+ $form['actions'] = array( | |
+ '#type' => 'actions', | |
+ '#weight' => 20, | |
+ ); | |
- // We don't have a "delete" action here. | |
- unset($actions['delete']); | |
+ $form['actions']['submit'] = array( | |
+ '#type' => 'submit', | |
+ '#value' => t('Save configuration'), | |
+ ); | |
- return $actions; | |
+ $form['#submit'][] = 'facetapi_realm_settings_form_submit'; | |
+ | |
+ return $form; | |
+ */ | |
} | |
+ | |
} | |
diff --git a/src/Form/IndexFieldsForm.php b/src/Form/IndexFieldsForm.php | |
index e53ecd6..404c995 100644 | |
--- a/src/Form/IndexFieldsForm.php | |
+++ b/src/Form/IndexFieldsForm.php | |
@@ -199,7 +199,6 @@ class IndexFieldsForm extends EntityForm { | |
); | |
$build['fields'][$key]['boost'] = array( | |
'#type' => 'select', | |
- '#options' => $boosts, | |
'#default_value' => sprintf('%.1f', $field->getBoost()), | |
'#states' => array( | |
'visible' => array( | |
@@ -210,6 +209,12 @@ class IndexFieldsForm extends EntityForm { | |
foreach ($fulltext_types as $type) { | |
$build['fields'][$key]['boost']['#states']['visible'][$css_key . '-type'][] = array('value' => $type); | |
} | |
+ | |
+ $build['fields'][$key]['facet'] = array( | |
+ '#type' => 'checkbox', | |
+ '#default_value' => $field->isFaceted(), | |
+ ); | |
+ | |
$build['fields'][$key]['#disabled'] = $field->isLocked(); | |
$build['fields'][$key]['#access'] = !$field->isHidden(); | |
} | |
@@ -261,6 +266,7 @@ class IndexFieldsForm extends EntityForm { | |
$field->setType($fields[$field_id]['type']); | |
$field->setBoost($fields[$field_id]['boost']); | |
$field->setIndexed((bool) $fields[$field_id]['indexed'], TRUE); | |
+ $field->setFaceted((bool) $fields[$field_id]['facet'], TRUE); | |
} | |
} | |
diff --git a/src/Item/Field.php b/src/Item/Field.php | |
index b961d2b..2858794 100644 | |
--- a/src/Item/Field.php | |
+++ b/src/Item/Field.php | |
@@ -53,6 +53,13 @@ class Field implements \IteratorAggregate, FieldInterface { | |
protected $boost; | |
/** | |
+ * The state of this field towards the facet implementation. | |
+ * | |
+ * @var bool | |
+ */ | |
+ protected $faceted; | |
+ | |
+ /** | |
* {@inheritdoc} | |
*/ | |
public function getType() { | |
@@ -156,6 +163,35 @@ class Field implements \IteratorAggregate, FieldInterface { | |
/** | |
* {@inheritdoc} | |
*/ | |
+ public function setFaceted($faceted, $notify = FALSE) { | |
+ $faceted = (bool) $faceted; | |
+ $this->faceted = $faceted; | |
+ if ($notify) { | |
+ $fields = $this->index->getOption('fields', array()); | |
+ if (isset($fields[$this->fieldIdentifier])) { | |
+ $fields[$this->fieldIdentifier]['faceted'] = $faceted; | |
+ $this->index->setOption('fields', $fields); | |
+ } | |
+ } | |
+ return $this; | |
+ } | |
+ | |
+ /** | |
+ * {@inheritdoc} | |
+ */ | |
+ public function isFaceted() { | |
+ if (!isset($this->faceted)) { | |
+ $fields = $this->index->getOption('fields', array()); | |
+ if (isset($fields[$this->fieldIdentifier])) { | |
+ $this->faceted = isset($fields[$this->fieldIdentifier]['boost']) ? (bool) $fields[$this->fieldIdentifier]['faceted'] : false; | |
+ } | |
+ } | |
+ return $this->faceted; | |
+ } | |
+ | |
+ /** | |
+ * {@inheritdoc} | |
+ */ | |
public function getBoost() { | |
if (!isset($this->boost)) { | |
$fields = $this->index->getOption('fields', array()); | |
diff --git a/src/Item/FieldInterface.php b/src/Item/FieldInterface.php | |
index c12c5c2..5f41966 100644 | |
--- a/src/Item/FieldInterface.php | |
+++ b/src/Item/FieldInterface.php | |
@@ -118,6 +118,27 @@ interface FieldInterface extends GenericFieldInterface, \Traversable { | |
public function getBoost(); | |
/** | |
+ * Sets whether this field is enabled to render facets from the results. | |
+ * | |
+ * @param bool $faceted | |
+ * The facet state of this field. | |
+ * @param bool $notify | |
+ * (optional) Whether to notify the index of the change, i.e., set the field | |
+ * to faceted in its options, too. | |
+ * | |
+ * @return $this | |
+ */ | |
+ public function setFaceted($faceted, $notify = FALSE); | |
+ | |
+ /** | |
+ * Retrieves wether or not the the field is enabled to render facets. | |
+ * | |
+ * @return bool $faceted | |
+ * The facet state of this field. | |
+ */ | |
+ public function isFaceted(); | |
+ | |
+ /** | |
* Sets the field's boost value. | |
* | |
* @param float $boost | |
diff --git a/src/Plugin/facet_api/adapter/Adapter.php b/src/Plugin/facet_api/adapter/Adapter.php | |
index 58e956e..ebe04ee 100644 | |
--- a/src/Plugin/facet_api/adapter/Adapter.php | |
+++ b/src/Plugin/facet_api/adapter/Adapter.php | |
@@ -1,9 +1,11 @@ | |
<?php | |
/** | |
- * Contains Drupal\facet_api\Plugin\TestAdapter | |
+ * Contains Drupal\search_api\Plugin\facet_api\adapter\Adapter | |
*/ | |
-namespace Drupal\search_api\Plugin\search_api\adapter; | |
+namespace Drupal\search_api\Plugin\facet_api\adapter; | |
+ | |
+use Drupal\facet_api\Adapter\AdapterPluginBase; | |
/** | |
* @FacetApiAdapter( | |
@@ -12,7 +14,7 @@ namespace Drupal\search_api\Plugin\search_api\adapter; | |
* description = @Translation("Search API Class for facet_api") | |
* ) | |
*/ | |
-class SearchApiFacetAdapter extends AdapterBase { | |
+class Adapter extends AdapterPluginBase { | |
/** | |
* Returns a boolean flagging whether $this->searcher['searcher'] executed a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment