diff --git a/src/Entity/Facet.php b/src/Entity/Facet.php index 0b7078a..f82541e 100644 --- a/src/Entity/Facet.php +++ b/src/Entity/Facet.php @@ -39,6 +39,7 @@ use Drupal\facets\FacetInterface; * "id", * "name", * "url_alias", + * "weight", * "show_only_one_result", * "field_identifier", * "query_type_name", diff --git a/src/FacetListBuilder.php b/src/FacetListBuilder.php index b843886..dca54cc 100644 --- a/src/FacetListBuilder.php +++ b/src/FacetListBuilder.php @@ -8,14 +8,14 @@ namespace Drupal\facets; use Drupal\Core\Config\Entity\ConfigEntityInterface; -use Drupal\Core\Config\Entity\DraggableListBuilder; +use Drupal\Core\Config\Entity\ConfigEntityListBuilder; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Link; /** * Builds a listing of facet entities. */ -class FacetListBuilder extends DraggableListBuilder { +class FacetListBuilder extends ConfigEntityListBuilder { /** * {@inheritdoc} @@ -113,7 +113,6 @@ class FacetListBuilder extends DraggableListBuilder { 'data' => $status_icon, 'class' => array('checkbox'), ), - 'weight' => array('data' => $row['weight']), 'operations' => $row['operations'], ), 'title' => $this->t('ID: @name', array('@name' => $entity->id())), @@ -137,7 +136,6 @@ class FacetListBuilder extends DraggableListBuilder { 'status' => array( 'data' => '', ), - 'weight' => array('data' => ''), 'operations' => array( 'data' => Link::createFromRoute( $this->t('Configure'), @@ -265,10 +263,4 @@ class FacetListBuilder extends DraggableListBuilder { }); } - /** - * {@inheritdoc} - */ - public function getFormId() { - return 'facets_list_builder'; - } } diff --git a/src/Form/FacetForm.php b/src/Form/FacetForm.php index 3870704..7d45955 100644 --- a/src/Form/FacetForm.php +++ b/src/Form/FacetForm.php @@ -215,6 +215,14 @@ class FacetForm extends EntityForm { ]; $this->buildFacetSourceConfigForm($form, $form_state); + $form['weight'] = [ + '#type' => 'number', + '#title' => $this->t('The weight of the facet'), + '#default_value' => $facet->getWeight(), + '#maxlength' => 4, + '#required' => TRUE, + ]; + $form['status'] = [ '#type' => 'checkbox', '#title' => $this->t('Enabled'), @@ -314,6 +322,8 @@ class FacetForm extends EntityForm { $facet->setOnlyVisibleWhenFacetSourceIsVisible(TRUE); } + $facet->setWeight((int) $form_state->getValue('weight')); + $facet_source_id = $form_state->getValue('facet_source_id'); if (!is_null($facet_source_id) && $facet_source_id !== '') { /** @var \Drupal\facets\FacetSource\FacetSourcePluginInterface $facet_source */ diff --git a/src/Tests/IntegrationTest.php b/src/Tests/IntegrationTest.php index 59cc009..9febcd1 100644 --- a/src/Tests/IntegrationTest.php +++ b/src/Tests/IntegrationTest.php @@ -178,6 +178,7 @@ class IntegrationTest extends FacetWebTestBase { 'status' => 1, 'facet_source_id' => 'search_api_views:search_api_test_view:page_1', 'facet_source_configs[search_api_views:search_api_test_view:page_1][field_identifier]' => 'type', + 'weight' => 4, ]; $this->drupalPostForm(NULL, ['facet_source_id' => 'search_api_views:search_api_test_view:page_1'], $this->t('Configure facet source')); $this->drupalPostForm(NULL, $form_values, $this->t('Save')); @@ -609,9 +610,11 @@ class IntegrationTest extends FacetWebTestBase { $this->drupalPostForm($facet_add_page, $form_values, $this->t('Save')); $this->assertText($this->t('Facet name field is required.')); $this->assertText($this->t('Facet source field is required.')); + $this->assertText($this->t('The weight of the facet field is required.')); // Make sure that when filling out the name, the form error disappears. $form_values['name'] = $facet_name; + $form_values['weight'] = 15; $this->drupalPostForm(NULL, $form_values, $this->t('Save')); $this->assertNoText($this->t('Facet name field is required.')); @@ -656,6 +659,7 @@ class IntegrationTest extends FacetWebTestBase { 'id' => $facet_id, 'url_alias' => $facet_id, 'facet_source_id' => 'search_api_views:search_api_test_view:page_1', + 'weight' => 7, ]; $facet_source_configs['facet_source_configs[search_api_views:search_api_test_view:page_1][field_identifier]'] = $facet_type;