Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
facets
Commits
272401d8
Commit
272401d8
authored
Mar 17, 2016
by
Joris Vercammen
Committed by
Joris Vercammen
Mar 17, 2016
Browse files
Issue
#2625208
by borisson_: Add ordering for facets to enable changing of url argument orders
parent
e3a8e5d6
Changes
10
Hide whitespace changes
Inline
Side-by-side
config/schema/facets.facet.schema.yml
View file @
272401d8
...
...
@@ -11,6 +11,9 @@ facets.facet.*:
uuid
:
type
:
string
label
:
'
UUID'
weight
:
type
:
integer
label
:
'
Weight'
status
:
type
:
boolean
label
:
'
Status'
...
...
core_search_facets/src/Tests/IntegrationTest.php
View file @
272401d8
...
...
@@ -250,6 +250,7 @@ class IntegrationTest extends CoreSearchFacetsWebTestBase {
'id'
=>
$facet_id
,
'status'
=>
1
,
'url_alias'
=>
$facet_id
,
'weight'
=>
4
,
];
// Try filling out the form, but without having filled in a name for the
...
...
@@ -286,7 +287,6 @@ class IntegrationTest extends CoreSearchFacetsWebTestBase {
$this
->
drupalGet
(
'admin/config/search/facets'
);
}
/**
* Tests editing of a facet through the UI.
*
...
...
src/Entity/Facet.php
View file @
272401d8
...
...
@@ -32,12 +32,14 @@ use Drupal\facets\FacetInterface;
* "id" = "id",
* "label" = "name",
* "uuid" = "uuid",
* "status" = "status"
* "status" = "status",
* "weight" = "weight"
* },
* config_export = {
* "id",
* "name",
* "url_alias",
* "weight",
* "show_only_one_result",
* "field_identifier",
* "query_type_name",
...
...
@@ -252,6 +254,14 @@ class Facet extends ConfigEntityBase implements FacetInterface {
*/
protected
$facetSourceConfig
;
/**
* The facet weight.
*
* @var integer
* The weight of the facet.
*/
protected
$weight
;
/**
* {@inheritdoc}
*/
...
...
@@ -748,4 +758,19 @@ class Facet extends ConfigEntityBase implements FacetInterface {
return
$this
->
facet_configs
;
}
/**
* {@inheritdoc}
*/
public
function
getWeight
()
{
return
$this
->
weight
;
}
/**
* {@inheritdoc}
*/
public
function
setWeight
(
$weight
)
{
$this
->
weight
=
$weight
;
return
$this
;
}
}
src/FacetInterface.php
View file @
272401d8
...
...
@@ -384,4 +384,17 @@ interface FacetInterface extends ConfigEntityInterface {
*/
public
function
setFacetConfigs
(
array
$facet_config
);
/**
* Returns the weight of the facet.
*/
public
function
getWeight
();
/**
* Sets the weight of the facet.
*
* @param int $weight
* Weight of the facet.
*/
public
function
setWeight
(
$weight
);
}
src/FacetListBuilder.php
View file @
272401d8
...
...
@@ -65,7 +65,7 @@ class FacetListBuilder extends ConfigEntityListBuilder {
* {@inheritdoc}
*/
public
function
buildHeader
()
{
return
[
$header
=
[
'type'
=>
$this
->
t
(
'Type'
),
'title'
=>
[
'data'
=>
$this
->
t
(
'Title'
),
...
...
@@ -74,7 +74,8 @@ class FacetListBuilder extends ConfigEntityListBuilder {
'data'
=>
$this
->
t
(
'Enabled'
),
'class'
=>
[
'checkbox'
],
],
]
+
parent
::
buildHeader
();
];
return
$header
+
parent
::
buildHeader
();
}
/**
...
...
@@ -167,8 +168,6 @@ class FacetListBuilder extends ConfigEntityListBuilder {
$list
[
'#attached'
][
'library'
][]
=
'facets/drupal.facets.admin_css'
;
$list
[
'#type'
]
=
'container'
;
$list
[
'facet_sources'
]
=
array
(
'#type'
=>
'table'
,
'#header'
=>
$this
->
buildHeader
(),
...
...
@@ -201,7 +200,8 @@ class FacetListBuilder extends ConfigEntityListBuilder {
$list
[
'lone_facets'
][
'table'
][
'#rows'
][
$entity
->
id
()]
=
$this
->
buildRow
(
$entity
);
}
}
return
$list
;
return
$list
+
parent
::
render
();
}
/**
...
...
src/Form/FacetForm.php
View file @
272401d8
...
...
@@ -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 */
...
...
src/Tests/ExampleContentTrait.php
View file @
272401d8
...
...
@@ -115,6 +115,7 @@ trait ExampleContentTrait {
'status'
=>
1
,
'url_alias'
=>
$id
,
'name'
=>
$name
,
'weight'
=>
2
,
'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]'
=>
$field
,
];
...
...
src/Tests/IntegrationTest.php
View file @
272401d8
...
...
@@ -8,6 +8,7 @@
namespace
Drupal\facets\Tests
;
use
Drupal\Core\Url
;
use
Drupal\facets\Entity\Facet
;
use
Drupal\facets\Tests\WebTestBase
as
FacetWebTestBase
;
/**
...
...
@@ -177,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'
));
...
...
@@ -462,6 +464,20 @@ class IntegrationTest extends FacetWebTestBase {
$this
->
assertLink
(
'(-) orange'
);
}
/**
* Tests facet weights.
*/
public
function
testWeight
()
{
$facet_name
=
"Forest owlet"
;
$id
=
"forest_owlet"
;
$this
->
addFacet
(
$facet_name
);
/** @var \Drupal\facets\FacetInterface $facet */
$facet
=
Facet
::
load
(
$id
);
$facet
->
setWeight
(
10
);
$this
->
assertEqual
(
10
,
$facet
->
getWeight
());
}
/**
* Deletes a facet block by id.
*
...
...
@@ -594,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.'
));
...
...
@@ -641,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
;
...
...
src/Tests/UrlIntegrationTest.php
View file @
272401d8
...
...
@@ -62,6 +62,7 @@ class UrlIntegrationTest extends FacetWebTestBase {
'status'
=>
1
,
'url_alias'
=>
$id
,
'name'
=>
$name
,
'weight'
=>
3
,
'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'
,
];
...
...
src/Tests/WidgetIntegrationTest.php
View file @
272401d8
...
...
@@ -59,6 +59,7 @@ class WidgetIntegrationTest extends FacetWebTestBase {
'status'
=>
1
,
'url_alias'
=>
$id
,
'name'
=>
$name
,
'weight'
=>
13
,
'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'
,
];
...
...
@@ -97,6 +98,7 @@ class WidgetIntegrationTest extends FacetWebTestBase {
'status'
=>
1
,
'url_alias'
=>
$id
,
'name'
=>
$name
,
'weight'
=>
12
,
'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'
,
];
...
...
@@ -111,6 +113,7 @@ class WidgetIntegrationTest extends FacetWebTestBase {
'status'
=>
1
,
'url_alias'
=>
$id_2
,
'name'
=>
$name_2
,
'weight'
=>
8
,
'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]'
=>
'keywords'
,
];
...
...
@@ -169,6 +172,7 @@ class WidgetIntegrationTest extends FacetWebTestBase {
'status'
=>
1
,
'url_alias'
=>
$id
,
'name'
=>
$name
,
'weight'
=>
11
,
'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'
,
];
...
...
@@ -208,6 +212,7 @@ class WidgetIntegrationTest extends FacetWebTestBase {
'status'
=>
1
,
'url_alias'
=>
$id
,
'name'
=>
$name
,
'weight'
=>
10
,
'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'
,
];
...
...
@@ -252,6 +257,7 @@ class WidgetIntegrationTest extends FacetWebTestBase {
'status'
=>
1
,
'url_alias'
=>
$id
,
'name'
=>
$name
,
'weight'
=>
9
,
'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'
,
];
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment