Skip to content
GitLab
Explore
Sign in
project
facets
Compare revisions
ba1d5de3c0f7f01deddd458c5e64a5599b82517e to 8.x-1.0-alpha1
Expand all
Hide whitespace changes
Inline
Side-by-side
phpunit.xml.dist
View file @
7bd666e7
...
...
@@ -8,7 +8,7 @@
<ini
name=
"memory_limit"
value=
"-1"
/>
</php>
<testsuites>
<testsuite
name=
"Facet
api
Test Suite"
>
<testsuite
name=
"Facet
s
Test Suite"
>
<directory>
./tests
</directory>
</testsuite>
</testsuites>
...
...
src/Annotation/FacetApiUrlProcessor.php
deleted
100644 → 0
View file @
ba1d5de3
<?php
/**
* @file
* Contains \Drupal\facetapi\Annotation\FacetApiUrlProcessor.
*/
namespace
Drupal\facetapi\Annotation
;
use
Drupal\Component\Annotation\Plugin
;
/**
* Defines a Facet API UrlProcessor annotation object.
*
* @see \Drupal\facetapi\UrlProcessor\UrlProcessorPluginManager
* @see plugin_api
*
* @ingroup plugin_api
*
* @Annotation
*/
class
FacetApiUrlProcessor
extends
Plugin
{
/**
* The facet_manager plugin id.
*
* @var string
*/
public
$id
;
/**
* The human-readable name of the url processor plugin.
*
* @ingroup plugin_translatable
*
* @var \Drupal\Core\Annotation\Translation
*/
public
$label
;
/**
* The url processor description.
*
* @ingroup plugin_translatable
*
* @var \Drupal\Core\Annotation\Translation
*/
public
$description
;
/**
* Class used to retrieve derivative definitions of the url processor.
*
* @var string
*/
public
$derivative
=
''
;
}
src/Annotation/Facet
Api
FacetSource.php
→
src/Annotation/Facet
s
FacetSource.php
View file @
7bd666e7
...
...
@@ -2,24 +2,24 @@
/**
* @file
* Contains \Drupal\facet
api
\Annotation\Facet
Api
Facet.
* Contains \Drupal\facet
s
\Annotation\Facet
s
Facet
Source
.
*/
namespace
Drupal\facet
api
\Annotation
;
namespace
Drupal\facet
s
\Annotation
;
use
Drupal\Component\Annotation\Plugin
;
/**
* Defines a Facet
API backend
annotation
object
.
* Defines a Facet
s facet source
annotation.
*
* @see \Drupal\facet
api
\FacetSource\FacetSourcePluginManager
* @see \Drupal\facet
api
\FacetSource\FacetSourceInterface
* @see \Drupal\facet
api
\FacetSource\FacetSourcePluginBase
* @see \Drupal\facet
s
\FacetSource\FacetSourcePluginManager
* @see \Drupal\facet
s
\FacetSource\FacetSource
Plugin
Interface
* @see \Drupal\facet
s
\FacetSource\FacetSourcePluginBase
* @see plugin_api
*
* @Annotation
*/
class
Facet
Api
FacetSource
extends
Plugin
{
class
Facet
s
FacetSource
extends
Plugin
{
/**
* The facet source plugin ID.
...
...
@@ -29,7 +29,7 @@ class FacetApiFacetSource extends Plugin {
public
$id
;
/**
* The human-readable name of the facet so
r
uce plugin.
* The human-readable name of the facet sou
r
ce plugin.
*
* @ingroup plugin_translatable
*
...
...
src/Annotation/Facet
Api
Processor.php
→
src/Annotation/Facet
s
Processor.php
View file @
7bd666e7
<?php
/**
* @file
* Contains \Drupal\facet
api
\Annotation\Facet
Api
Processor.
* Contains \Drupal\facet
s
\Annotation\Facet
s
Processor.
*/
namespace
Drupal\facet
api
\Annotation
;
namespace
Drupal\facet
s
\Annotation
;
use
Drupal\Component\Annotation\Plugin
;
/**
* Defines a Facet
API
Processor annotation
object
.
* Defines a Facet
s
Processor annotation.
*
* @see \Drupal\facet
api
\Processor\ProcessorPluginManager
* @see \Drupal\facet
s
\Processor\ProcessorPluginManager
* @see plugin_api
*
* @ingroup plugin_api
*
* @Annotation
*/
class
Facet
Api
Processor
extends
Plugin
{
class
Facet
s
Processor
extends
Plugin
{
/**
* The processor plugin id.
...
...
@@ -58,7 +58,7 @@ class FacetApiProcessor extends Plugin {
* This is represented as an associative array, mapping one or more of the
* stage identifiers to the default weight for that stage. For the available
* stages, see
* \Drupal\facet
api
\Processor\ProcessorPluginManager::getProcessingStages().
* \Drupal\facet
s
\Processor\ProcessorPluginManager::getProcessingStages().
*
* @var int[]
*/
...
...
src/Annotation/Facet
Api
QueryType.php
→
src/Annotation/Facet
s
QueryType.php
View file @
7bd666e7
...
...
@@ -2,24 +2,24 @@
/**
* @file
* Contains \Drupal\facet
api
\Annotation\Facet
Api
QueryType.
* Contains \Drupal\facet
s
\Annotation\Facet
s
QueryType.
*/
namespace
Drupal\facet
api
\Annotation
;
namespace
Drupal\facet
s
\Annotation
;
use
Drupal\Component\Annotation\Plugin
;
/**
* Defines a Facet
API Q
uery
T
ype annotation
object
.
* Defines a Facet
s q
uery
t
ype annotation.
*
* @see \Drupal\facet
api
\QueryType\QueryTypePluginManager
* @see \Drupal\facet
s
\QueryType\QueryTypePluginManager
* @see plugin_api
*
* @ingroup plugin_api
*
* @Annotation
*/
class
Facet
Api
QueryType
extends
Plugin
{
class
Facet
s
QueryType
extends
Plugin
{
/**
* The query type plugin id.
...
...
src/Annotation/Facet
ApiEmptyBehavi
or.php
→
src/Annotation/Facet
sUrlProcess
or.php
View file @
7bd666e7
<?php
/**
* @file
* Contains \Drupal\facet
api
\Annotation\Facet
ApiEmptyBehavi
or.
* Contains \Drupal\facet
s
\Annotation\Facet
sUrlProcess
or.
*/
namespace
Drupal\facet
api
\Annotation
;
namespace
Drupal\facet
s
\Annotation
;
use
Drupal\Component\Annotation\Plugin
;
/**
* Defines a Facet
API EmptyBehavi
or annotation
object
.
* Defines a Facet
s URL Process
or annotation.
*
* @see \Drupal\facet
api\EmptyBehavior\EmptyBehavi
orPluginManager
* @see \Drupal\facet
s\Processor\Process
orPluginManager
* @see plugin_api
*
* @ingroup plugin_api
*
* @Annotation
*/
class
Facet
ApiEmptyBehavi
or
extends
Plugin
{
class
Facet
sUrlProcess
or
extends
Plugin
{
/**
* The
empty behavi
or plugin
ID
.
* The
URL process
or plugin
id
.
*
* @var string
*/
public
$id
;
/**
* The human-readable name of the
empty behavi
or plugin.
* The human-readable name of the
URL process
or plugin.
*
* @ingroup plugin_translatable
*
...
...
@@ -38,7 +37,7 @@ class FacetApiEmptyBehavior extends Plugin {
public
$label
;
/**
* The
empty behavi
or description.
* The
URL process
or description.
*
* @ingroup plugin_translatable
*
...
...
src/Annotation/Facet
Api
Widget.php
→
src/Annotation/Facet
s
Widget.php
View file @
7bd666e7
...
...
@@ -2,24 +2,24 @@
/**
* @file
* Contains \Drupal\facet
api
\Annotation\Facet
Api
Widget.
* Contains \Drupal\facet
s
\Annotation\Facet
s
Widget.
*/
namespace
Drupal\facet
api
\Annotation
;
namespace
Drupal\facet
s
\Annotation
;
use
Drupal\Component\Annotation\Plugin
;
/**
* Defines a Facet
API
Widget annotation
object
.
* Defines a Facet
s
Widget annotation.
*
* @see \Drupal\facet
api
\Widget\WidgetPluginManager
* @see \Drupal\facet
s
\Widget\WidgetPluginManager
* @see plugin_api
*
* @ingroup plugin_api
*
* @Annotation
*/
class
Facet
Api
Widget
extends
Plugin
{
class
Facet
s
Widget
extends
Plugin
{
/**
* The widget plugin id.
...
...
src/ContextProvider/FacetContextProvider.php
deleted
100644 → 0
View file @
ba1d5de3
<?php
/**
* @file
* Contains \Drupal\facetapi\ContextProvider\FacetContextProvider.
*/
namespace
Drupal\facetapi\ContextProvider
;
use
Drupal\Core\Entity\EntityTypeManagerInterface
;
use
Drupal\Core\Plugin\Context\Context
;
use
Drupal\Core\Plugin\Context\ContextDefinition
;
use
Drupal\Core\Plugin\Context\ContextProviderInterface
;
use
Drupal\Core\StringTranslation\StringTranslationTrait
;
/**
*
*/
class
FacetContextProvider
implements
ContextProviderInterface
{
use
StringTranslationTrait
;
protected
$facetStorage
;
/**
* Create a new instance of the context provider.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
*/
public
function
__construct
(
EntityTypeManagerInterface
$entity_type_manager
)
{
$this
->
facetStorage
=
$entity_type_manager
->
getStorage
(
'facetapi_facet'
);
}
/**
* {@inheritdoc}
*/
public
function
getRuntimeContexts
(
array
$unqualified_context_ids
=
[])
{
$ids
=
$this
->
facetStorage
->
getQuery
()
->
condition
(
'uuid'
,
$unqualified_context_ids
,
'IN'
)
->
execute
();
$contexts
=
[];
foreach
(
$this
->
facetStorage
->
loadMultiple
(
$ids
)
as
$facet
)
{
$context
=
new
Context
(
new
ContextDefinition
(
'entity:facetapi_facet'
),
$facet
);
$contexts
[
$facet
->
uuid
()]
=
$context
;
}
return
$contexts
;
}
/**
* {@inheritdoc}
*/
public
function
getAvailableContexts
()
{
$facets
=
$this
->
facetStorage
->
loadMultiple
();
$contexts
=
[];
/** @var \Drupal\facetapi\FacetInterface $facet */
foreach
(
$facets
as
$facet
)
{
$context
=
new
Context
(
new
ContextDefinition
(
'entity:facetapi_facet'
,
$facet
->
label
()),
$facet
);
$contexts
[
$facet
->
uuid
()]
=
$context
;
}
return
$contexts
;
}
}
src/Controller/FacetController.php
View file @
7bd666e7
...
...
@@ -2,14 +2,14 @@
/**
* @file
* Contains \Drupal\facet
api
\Controller\FacetController.
* Contains \Drupal\facet
s
\Controller\FacetController.
*/
namespace
Drupal\facet
api
\Controller
;
namespace
Drupal\facet
s
\Controller
;
use
Drupal\Component\Render\FormattableMarkup
;
use
Drupal\Core\Controller\ControllerBase
;
use
Drupal\facet
api
\FacetInterface
;
use
Drupal\facet
s
\FacetInterface
;
/**
* Provides route responses for facets.
...
...
@@ -19,7 +19,7 @@ class FacetController extends ControllerBase {
/**
* Displays information about a search facet.
*
* @param \Drupal\facet
api
\FacetInterface $facet
* @param \Drupal\facet
s
\FacetInterface $facet
* The facet to display.
*
* @return array
...
...
@@ -29,7 +29,7 @@ class FacetController extends ControllerBase {
// Build the search index information.
$render
=
array
(
'view'
=>
array
(
'#theme'
=>
'facet
api
_facet'
,
'#theme'
=>
'facet
s
_facet'
,
'#facet'
=>
$facet
,
),
);
...
...
@@ -39,37 +39,32 @@ class FacetController extends ControllerBase {
/**
* Returns a form to add a new facet to a search api index.
*
* @param \Drupal\search_api\IndexInterface $search_api_index
* The search api index this facet will be added to.
*
* @return array
* The facet add form.
*/
public
function
addForm
()
{
$facet
=
\Drupal
::
service
(
'entity_type.manager'
)
->
getStorage
(
'facet
api
_facet'
)
->
create
();
$facet
=
\Drupal
::
service
(
'entity_type.manager'
)
->
getStorage
(
'facet
s
_facet'
)
->
create
();
return
$this
->
entityFormBuilder
()
->
getForm
(
$facet
,
'default'
);
}
/**
* Returns a form to edit a facet on a search api index.
*
* @param \Drupal\search_api\IndexInterface $search_api_index
* The search api index this facet will be added to.
* @param \Drupal\facetapi\FacetInterface $facetapi_facet
* Facet currently being edited
* @param \Drupal\facets\FacetInterface $facets_facet
* Facet currently being edited.
*
* @return array
* The facet edit form.
*/
public
function
editForm
(
FacetInterface
$facet
api
_facet
)
{
$facet
=
\Drupal
::
service
(
'entity_type.manager'
)
->
getStorage
(
'facet
api
_facet'
)
->
load
(
$facet
api
_facet
->
id
());
public
function
editForm
(
FacetInterface
$facet
s
_facet
)
{
$facet
=
\Drupal
::
service
(
'entity_type.manager'
)
->
getStorage
(
'facet
s
_facet'
)
->
load
(
$facet
s
_facet
->
id
());
return
$this
->
entityFormBuilder
()
->
getForm
(
$facet
,
'default'
);
}
/**
* Returns the page title for an facets's "View" tab.
*
* @param \Drupal\facet
api/
FacetInterface $facet
* @param \Drupal\facet
s\
FacetInterface $facet
* The facet that is displayed.
*
* @return string
...
...
src/Controller/FacetSourceController.php
0 → 100644
View file @
7bd666e7
<?php
/**
* @file
* Contains \Drupal\facets\Controller\FacetSourceController.
*/
namespace
Drupal\facets\Controller
;
use
Drupal\Core\Controller\ControllerBase
;
/**
* Provides route responses for facet source configuration.
*/
class
FacetSourceController
extends
ControllerBase
{
/**
* Configuration for the facet source.
*
* @param string $source_id
* The plugin id.
*
* @return array
* A renderable array containing the form.
*/
public
function
facetSourceConfigForm
(
$source_id
)
{
// Returns the render array of the FacetSourceConfigForm.
return
$this
->
formBuilder
()
->
getForm
(
'\Drupal\facets\Form\FacetSourceEditForm'
);
}
}
src/EmptyBehavior/EmptyBehaviorInterface.php
deleted
100644 → 0
View file @
ba1d5de3
<?php
/**
* @file
* Contains Drupal\facetap\EmptyBehavior\EmptyBehaviorInterface.
*/
namespace
Drupal\facetapi\EmptyBehavior
;
use
Drupal\Component\Plugin\PluginInspectionInterface
;
use
Drupal\Core\Plugin\PluginFormInterface
;
/**
* Specifies the publicly available methods of an empty behavior plugin.
*
* @see \Drupal\facetapi\Annotation\FacetApiEmptyBehavior
* @see \Drupal\facetapi\Plugin\EmptyBehavior\EmptyBehaviorPluginManager
* @see \Drupal\facetapi\Plugin\EmptyBehavior\EmptyBehaviorInterface
* @see plugin_api
*/
interface
EmptyBehaviorInterface
extends
PluginInspectionInterface
,
PluginFormInterface
{
/**
* Returns the render array used for the facet that is empty, or has no items.
*
* @param array $facet_empty_behavior_configs
* Configuration for the empty behavior.
*
* @return
* The element's render array.
*/
public
function
build
(
array
$facet_empty_behavior_configs
);
}
src/EmptyBehavior/EmptyBehaviorPluginBase.php
deleted
100644 → 0
View file @
ba1d5de3
<?php
/**
* @file
* Contains \Drupal\facetapi\EmptyBehavior\EmptyBehaviorPluginBase.
*/
namespace
Drupal\facetapi\EmptyBehavior
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Plugin\ContainerFactoryPluginInterface
;
use
Drupal\Core\Plugin\PluginBase
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
/**
* Common base class for empty behavior plugins.
*
* @see \Drupal\facetapi\Annotation\FacetApiEmptyBehavior
* @see \Drupal\facetapi\Plugin\EmptyBehavior\EmptyBehaviorPluginManager
* @see \Drupal\facetapi\Plugin\EmptyBehavior\EmptyBehaviorInterface
* @see plugin_api
*/
abstract
class
EmptyBehaviorPluginBase
extends
PluginBase
implements
EmptyBehaviorInterface
,
ContainerFactoryPluginInterface
{
/**
* The configuration factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected
$configFactory
;
/**
* Constructs a EmptyBehaviorPluginBase object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration factory.
*/
public
function
__construct
(
array
$configuration
,
$plugin_id
,
$plugin_definition
,
$config_factory
)
{
parent
::
__construct
(
$configuration
,
$plugin_id
,
$plugin_definition
);
$this
->
configFactory
=
$config_factory
;
}
/**
* {@inheritdoc}
*/
public
static
function
create
(
ContainerInterface
$container
,
array
$configuration
,
$plugin_id
,
$plugin_definition
)
{
/** @var \Drupal\Core\Config\ConfigFactoryInterface $config_factory */
$config_factory
=
$container
->
get
(
'config.factory'
);
return
new
static
(
$configuration
,
$plugin_id
,
$plugin_definition
,
$config_factory
);
}
/**
* {@inheritdoc}
*/
public
function
build
(
array
$config
)
{
return
[];
}
/**
* {@inheritdoc}
*/
public
function
buildConfigurationForm
(
array
$form
,
FormStateInterface
$form_state
)
{
return
FALSE
;
}
/**
* {@inheritdoc}
*/
public
function
validateConfigurationForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{}
/**
* {@inheritdoc}
*/
public
function
submitConfigurationForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{}
}
src/Entity/Facet.php
View file @
7bd666e7
This diff is collapsed.
Click to expand it.
src/Entity/FacetSource.php
0 → 100644
View file @
7bd666e7
<?php
/**
* @file
* Contains \Drupal\facets\Entity\FacetSource.
*/
namespace
Drupal\facets\Entity
;
use
Drupal\Core\Config\Entity\ConfigEntityBase
;
use
Drupal\facets\FacetSourceInterface
;
/**
* Defines the facet source configuration entity.
*
* @ConfigEntityType(
* id = "facets_facet_source",
* label = @Translation("Facet source"),
* handlers = {
* "storage" = "Drupal\Core\Config\Entity\ConfigEntityStorage",
* "list_builder" = "Drupal\facets\FacetListBuilder",
* "form" = {
* "default" = "Drupal\facets\Form\FacetSourceEditForm",
* "edit" = "Drupal\facets\Form\FacetSourceEditForm",
* "display" = "Drupal\facets\Form\FacetSourceDisplayForm",
* "delete" = "Drupal\facets\Form\FacetSourceDeleteConfirmForm",
* },
* },
* admin_permission = "administer facets",
* config_prefix = "facet_source",
* entity_keys = {
* "id" = "id",
* "label" = "name",
* "uuid" = "uuid"
* },
* config_export = {
* "id",
* "name",
* "filter_key",
* "url_processor"
* },
* links = {
* "canonical" = "/admin/config/search/facets/facet-sources/",
* "edit-form" = "/admin/config/search/facets/facet-sources/{facets_facet_source}/edit"
* }
* )
*/
class
FacetSource
extends
ConfigEntityBase
implements
FacetSourceInterface
{
/**
* The ID of the facet source.
*
* @var string
*/
protected
$id
;
/**
* A name to be displayed for the facet source.
*
* @var string
*/
protected
$name
;
/**
* The key, used for filters in the query string.
*
* @var string
*/
protected
$filter_key
;
/**
* The url processor name.
*
* @var string
*/
protected
$url_processor
=
'query_string'
;
/**
* {@inheritdoc}
*/
public
function
getName
()
{
return
$this
->
name
;
}
/**
* {@inheritdoc}
*/
public
function
setFilterKey
(
$filter_key
)
{
$this
->
filter_key
=
$filter_key
;
}
/**
* {@inheritdoc}
*/
public
function
getFilterKey
()
{
return
$this
->
filter_key
;
}
/**
* {@inheritdoc}
*/
public
function
setUrlProcessor
(
$processor_name
)
{
$this
->
url_processor
=
$processor_name
;
}
/**
* {@inheritdoc}
*/
public
function
getUrlProcessorName
()
{
return
$this
->
url_processor
;
}
}
src/Exception/Exception.php
View file @
7bd666e7
...
...
@@ -2,12 +2,12 @@
/**
* @file
* Contains \Drupal\facet
api
\Exception\Exception.
* Contains \Drupal\facet
s
\Exception\Exception.
*/
namespace
Drupal\facet
api
\Exception
;
namespace
Drupal\facet
s
\Exception
;
/**
* Represents an exception that occurred in some part of the Facet
API
.
* Represents an exception that occurred in some part of the Facet
s
.
*/
class
Exception
extends
\Exception
{}
src/Exception/InvalidProcessorException.php
View file @
7bd666e7
...
...
@@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\facet
api
\Exception\InvalidProcessorException.
* Contains \Drupal\facet
s
\Exception\InvalidProcessorException.
*/
namespace
Drupal\facet
api
\Exception
;
namespace
Drupal\facet
s
\Exception
;
/**
* Represents an exception that occurred when calling an invalid processor.
...
...
src/Exception/InvalidQueryTypeException.php
View file @
7bd666e7
...
...
@@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\facet
api
\Exception\InvalidQueryTypeException.
* Contains \Drupal\facet
s
\Exception\InvalidQueryTypeException.
*/
namespace
Drupal\facet
api
\Exception
;
namespace
Drupal\facet
s
\Exception
;
/**
* Represents an exception that occurred when calling an invalid query type.
...
...
src/FacetInterface.php
View file @
7bd666e7
<?php
/**
* @file
* Contains Drupal\facet
api
\FacetInterface.
* Contains Drupal\facet
s
\FacetInterface.
*/
namespace
Drupal\facet
api
;
namespace
Drupal\facet
s
;
use
Drupal\Core\Config\Entity\ConfigEntityInterface
;
/**
*
*
The facet entity.
*/
interface
FacetInterface
extends
ConfigEntityInterface
{
...
...
@@ -16,8 +17,10 @@ interface FacetInterface extends ConfigEntityInterface {
* Sets the facet's widget plugin id.
*
* @param string $widget
* The widget plugin id.
*
* @return $this
* Returns self
*/
public
function
setWidget
(
$widget
);
...
...
@@ -25,159 +28,161 @@ interface FacetInterface extends ConfigEntityInterface {
* Returns the facet's widget plugin id.
*
* @return string
* The widget plugin id.
*/
public
function
getWidget
();
/**
*
G
et field identifier.
*
R
et
urns
field identifier.
*
* @return string
* The field identifier of this facet.
*/
public
function
getFieldIdentifier
();
/**
* Sets
the empty_behavior id
.
* Sets
field identifier
.
*
* @param
$behavior_id
* The
id for the empty behavior
.
* @param
string $field_identifier
* The
field identifier of this facet
.
*
* @return mixed
* @return $this
* Returns self.
*/
public
function
setField
EmptyBehavior
(
$behavior_id
);
public
function
setField
Identifier
(
$field_identifier
);
/**
*
G
et
field empty_behavior
.
*
R
et
urns the field alias used to identify the facet in the url
.
*
* @return mixed
* @return string
* The field alias for the facet.
*/
public
function
getField
EmptyBehavior
();
public
function
getField
Alias
();
/**
*
S
et
field identifier
.
*
R
et
urns the field name of the facet as used in the index
.
*
* @return mixed
* @TODO: Check if fieldIdentifier can be used as well!
*
* @return string
* The name of the facet.
*/
public
function
setFieldIdentifier
(
$field_identifier
);
public
function
getName
(
);
/**
*
G
et the
field alias used to identify
the facet in the
url
.
*
R
et
urns
the
name of
the facet
for use
in the
URL
.
*
* @return mixed
* @return string
* The name of the facet for use in the URL.
*/
public
function
get
Field
Alias
();
public
function
get
Url
Alias
();
/**
*
G
et the
field
name of the facet
as
use
d
in the
index
.
*
S
et
s
the name of the facet
for
use in the
URL
.
*
* @TODO: Check if fieldIdentifier can be used as well!
*
* @return mixed
* @param string $url_alias
* The name of the facet for use in the URL.
*/
public
function
getName
();
public
function
setUrlAlias
(
$url_alias
);
/**
* Sets an item with value to active.
*
* @param $value
* @param string $value
* An item that is active.
*/
public
function
setActiveItem
(
$value
);
/**
*
G
et all the active items in the facet.
*
R
et
urns
all the active items in the facet.
*
* @return mixed
* An array containing all active items.
*/
public
function
getActiveItems
();
/**
* Check if a value is active.
* Check
s
if a value is active.
*
* @param string $value
* The value to be checked.
*
* @return bool
* Is an active value.
*/
public
function
isActiveValue
(
$value
);
/**
*
G
et the result for the facet.
*
R
et
urns
the result for the facet.
*
* @return ResultInterface[] $results
* @return \Drupal\facets\Result\ResultInterface[] $results
* The results of the facet.
*/
public
function
getResults
();
/**
* Sets the re
u
slts for the facet.
* Sets the res
u
lts for the facet.
*
* @param ResultInterface[] $results
* @param \Drupal\facets\Result\ResultInterface[] $results
* The results of the facet.
*/
public
function
setResults
(
array
$results
);
/**
*
G
et
the query type instance
.
*
S
et
s an array of unfiltered results
.
*
* @return string
*/
public
function
getQueryType
();
/**
* Get the plugin name for the url processor.
* These unfiltered results are used to set the correct count of the actual
* facet results when using the OR query operator. They are not results value
* objects like those in ::$results.
*
* @return mixed
* @param array $all_results
* Unfiltered results.
*/
public
function
g
etU
rlProcessorName
(
);
public
function
s
etU
nfilteredResults
(
array
$all_results
=
[]
);
/**
* Retrieves an option.
*
* @param string $name
* The name of an option.
* @param mixed $default
* The value return if the option wasn't set.
* Returns an array of unfiltered results.
*
* @return mixed
* The value of the option.
*
* @see getOptions()
* @return array
* Unfiltered results.
*/
public
function
get
Option
(
$name
,
$default
=
NULL
);
public
function
get
UnfilteredResults
(
);
/**
* Ret
rieves an array of all options
.
* Ret
urns the query type instance
.
*
* @return
array
*
An associative array of option values, keyed by the option name
.
* @return
string
*
The query type plugin being used
.
*/
public
function
get
Options
();
public
function
get
QueryType
();
/**
* Sets an option.
*
* @param string $name
* The name of an option.
* @param mixed $option
* The new option.
* Returns the query operator.
*
* @return $this
* @return string
* The query operator being used.
*/
public
function
s
et
Option
(
$name
,
$option
);
public
function
g
et
QueryOperator
(
);
/**
*
S
ets the
index's options
.
*
R
et
urn
s the
value of the exclude boolean
.
*
* @param array $options
* The new index options.
* This will return true when the current facet's value should be exclusive
* from the search rather than inclusive.
* When this returns TRUE, the operator will be "<>" instead of "=".
*
* @return $this
* @return bool
* A boolean flag indicating if search should exlude selected facets
*/
public
function
setOptions
(
array
$options
);
public
function
getExclude
();
/**
*
G
ets the
facet manager plugin id
.
*
R
et
urn
s the
plugin name for the url processor
.
*
* @return string
* The id of the url processor.
*/
public
function
get
ManagerPluginId
();
public
function
get
UrlProcessorName
();
/**
* Sets a string representation of the Facet source plugin.
...
...
@@ -185,55 +190,72 @@ interface FacetInterface extends ConfigEntityInterface {
* This is usually the name of the Search-api view.
*
* @param string $facet_source_id
* The facet source id.
*
* @return $this
* Returns self.
*/
public
function
setFacetSourceId
(
$facet_source_id
);
/**
* Sets the query operator.
*
* @param string $operator
* The query operator being used.
*/
public
function
setQueryOperator
(
$operator
);
/**
* Sets the exclude.
*
* @param bool $exclude
* A boolean flag indicating if search should exclude selected facets
*/
public
function
setExclude
(
$exclude
);
/**
* Returns the Facet source id.
*
* @return string
* The id of the facet source.
*/
public
function
getFacetSourceId
();
/**
* Returns the plugin instance of a facet source.
*
* @return \Drupal\facet
api
\FacetSource\FacetSourceInterface
* @return \Drupal\facet
s
\FacetSource\FacetSource
Plugin
Interface
* The plugin instance for the facet source.
*/
public
function
getFacetSource
();
/**
* Load the facet sources for this facet.
*
* @param bool|TRUE $only_enabled
* Returns the facet source configuration object.
*
* @return FacetSourceInterface[]
* @return \Drupal\facets\FacetSourceInterface
* A facet source configuration object.
*/
public
function
getFacetSource
s
(
$only_enabled
=
TRUE
);
public
function
getFacetSource
Config
(
);
/**
*
Get the path to which
th
e
facet
should link
.
*
Loads the facet sources for
th
is
facet.
*
* @param string $path
*/
public
function
setPath
(
$path
);
/**
* Get the path to which the facet should link.
* @param bool|TRUE $only_enabled
* Only return enabled facet sources.
*
* @return NULL|string
* @return \Drupal\facets\FacetSource\FacetSourcePluginInterface[]
* An array of facet sources.
*/
public
function
get
Path
(
);
public
function
get
FacetSources
(
$only_enabled
=
TRUE
);
/**
* Returns an array of processors with their configuration.
*
* @param bool|TRUE $only_enabled
* Only return enabled processors.
*
* @return \Drupal\facetapi\Processor\ProcessorInterface[]
* @return \Drupal\facets\Processor\ProcessorInterface[]
* An array of processors.
*/
public
function
getProcessors
(
$only_enabled
=
TRUE
);
...
...
@@ -242,18 +264,26 @@ interface FacetInterface extends ConfigEntityInterface {
*
* @param string $stage
* The stage for which to return the processors. One of the
* \Drupal\facet
api
\Processor\ProcessorInterface::STAGE_* constants.
* \Drupal\facet
s
\Processor\ProcessorInterface::STAGE_* constants.
* @param bool $only_enabled
* (optional) If FALSE, also include disabled processors. Otherwise, only
* load enabled ones.
*
* @return \Drupal\facet
api
\Processor\ProcessorInterface[]
* @return \Drupal\facet
s
\Processor\ProcessorInterface[]
* An array of all enabled (or available, if if $only_enabled is FALSE)
* processors that support the given stage, ordered by the weight for that
* stage.
*/
public
function
getProcessorsByStage
(
$stage
,
$only_enabled
=
TRUE
);
/**
* Retrieves this facets's processor configs.
*
* @return array
* An array of processors and their configs.
*/
public
function
getProcessorConfigs
();
/**
* Sets the "only visible when facet source is visible" boolean flag.
*
...
...
@@ -262,14 +292,80 @@ interface FacetInterface extends ConfigEntityInterface {
* does not show the facet source.
*
* @return $this
* Returns self.
*/
public
function
setOnlyVisibleWhenFacetSourceIsVisible
(
$only_visible_when_facet_source_is_visible
);
/**
* Returns the "only visible when facet source is visible" boolean flag.
*
* @return boolean
* @return bool
* True when the facet is only shown on a page with the facet source.
*/
public
function
getOnlyVisibleWhenFacetSourceIsVisible
();
/**
* Adds a processor for this facet.
*
* @param array $processor
* An array definition for a processor.
*/
public
function
addProcessor
(
array
$processor
);
/**
* Removes a processor for this facet.
*
* @param string $processor_id
* The plugin id of the processor.
*/
public
function
removeProcessor
(
$processor_id
);
/**
* Defines the no-results behavior.
*
* @param array $behavior
* The definition of the behavior.
*/
public
function
setEmptyBehavior
(
array
$behavior
);
/**
* Returns the defined no-results behavior or NULL if none defined.
*
* @return array|NULL
* The behavior definition or NULL.
*/
public
function
getEmptyBehavior
();
/**
* Returns the configuration of the selected widget.
*
* @return array
* The configuration settings for the widget.
*/
public
function
getWidgetConfigs
();
/**
* Sets the configuration for the widget of this facet.
*
* @param array $widget_config
* The configuration settings for the widget.
*/
public
function
setWidgetConfigs
(
array
$widget_config
);
/**
* Returns any additional configuration for this facet, not defined above.
*
* @return array
* An array of additional configuration for the facet.
*/
public
function
getFacetConfigs
();
/**
* Defines any additional configuration for this facet not defined above.
*
* @param array $facet_config
* An array of additional configuration for the facet.
*/
public
function
setFacetConfigs
(
array
$facet_config
);
}
src/FacetListBuilder.php
View file @
7bd666e7
...
...
@@ -2,15 +2,15 @@
/**
* @file
* Contains \Drupal\facet
api
\FacetListBuilder.
* Contains \Drupal\facet
s
\FacetListBuilder.
*/
namespace
Drupal\facet
api
;
namespace
Drupal\facet
s
;
use
Drupal\Core\Config\Entity\ConfigEntityInterface
;
use
Drupal\Core\Config\Entity\ConfigEntityListBuilder
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\
facetapi\FacetSource\FacetSourceInterface
;
use
Drupal\
Core\Link
;
/**
* Builds a listing of facet entities.
...
...
@@ -81,7 +81,7 @@ class FacetListBuilder extends ConfigEntityListBuilder {
* {@inheritdoc}
*/
public
function
buildRow
(
EntityInterface
$entity
)
{
/** @var \Drupal\
Core\Config\Entity\ConfigEntity
Interface $entity */
/** @var \Drupal\
facets\Facet
Interface $entity */
$row
=
parent
::
buildRow
(
$entity
);
$status_label
=
$entity
->
status
()
?
$this
->
t
(
'Enabled'
)
:
$this
->
t
(
'Disabled'
);
...
...
@@ -98,14 +98,14 @@ class FacetListBuilder extends ConfigEntityListBuilder {
'data'
=>
array
(
'type'
=>
array
(
'data'
=>
'Facet'
,
'class'
=>
array
(
'facet
api
-type'
),
'class'
=>
array
(
'facet
s
-type'
),
),
'title'
=>
array
(
'data'
=>
array
(
'#type'
=>
'link'
,
'#title'
=>
$entity
->
getName
(),
'#suffix'
=>
'<div>'
.
$entity
->
getFieldAlias
()
.
' - '
.
$entity
->
getWidget
()
.
'</div>'
,
)
+
$entity
->
urlInfo
(
'edit-form'
)
->
toRenderArray
(),
'#type'
=>
'link'
,
'#title'
=>
$entity
->
getName
(),
'#suffix'
=>
'<div>'
.
$entity
->
getFieldAlias
()
.
' - '
.
$entity
->
getWidget
()
.
'</div>'
,
)
+
$entity
->
urlInfo
(
'edit-form'
)
->
toRenderArray
(),
'class'
=>
array
(
'search-api-title'
),
),
'status'
=>
array
(
...
...
@@ -120,14 +120,14 @@ class FacetListBuilder extends ConfigEntityListBuilder {
}
/**
*
{@inheritdoc}
*
Builds an array of facet sources for display in the overview.
*/
public
function
buildFacetSourceRow
(
array
$facet_source
=
[])
{
return
array
(
'data'
=>
array
(
'type'
=>
array
(
'data'
=>
'Facet source'
,
'class'
=>
array
(
'facet
api
-type'
),
'class'
=>
array
(
'facet
s
-type'
),
),
'title'
=>
array
(
'data'
=>
$facet_source
[
'id'
],
...
...
@@ -135,7 +135,13 @@ class FacetListBuilder extends ConfigEntityListBuilder {
'status'
=>
array
(
'data'
=>
''
,
),
'operations'
=>
array
(),
'operations'
=>
array
(
'data'
=>
Link
::
createFromRoute
(
$this
->
t
(
'Configure'
),
'entity.facets_facet_source.edit_form'
,
[
'source_id'
=>
$facet_source
[
'id'
]]
)
->
toRenderable
(),
),
),
'class'
=>
array
(
'facet-source'
),
);
...
...
@@ -154,12 +160,12 @@ class FacetListBuilder extends ConfigEntityListBuilder {
'#markup'
=>
$this
->
t
(
'You currently have no facet sources defined. You should start by adding a facet source before creating facets.<br />
An example of a facet source is a view based on Search API or a Search API page.
Other modules can also implement a facet source by providing a plugin that implements the FacetSourceInterface.'
)
Other modules can also implement a facet source by providing a plugin that implements the FacetSource
Plugin
Interface.'
)
,
];
}
$list
[
'#attached'
][
'library'
][]
=
'facet
api
/drupal.facet
api
.admin_css'
;
$list
[
'#attached'
][
'library'
][]
=
'facet
s
/drupal.facet
s
.admin_css'
;
$list
[
'#type'
]
=
'container'
;
...
...
@@ -169,7 +175,9 @@ class FacetListBuilder extends ConfigEntityListBuilder {
'#rows'
=>
array
(),
'#empty'
=>
$groups
[
'lone_facets'
]
?
''
:
$this
->
t
(
'There are no facet sources or facets defined.'
),
'#attributes'
=>
array
(
'id'
=>
'facetapi-groups-list'
,
'class'
=>
array
(
'facets-groups-list'
,
),
),
);
...
...
@@ -206,7 +214,7 @@ class FacetListBuilder extends ConfigEntityListBuilder {
* - lone_facets: All facets that aren't attached to any facet source.
*/
public
function
loadGroups
()
{
$facet_source_plugin_manager
=
\Drupal
::
service
(
'plugin.manager.facet
api
.facet_source'
);
$facet_source_plugin_manager
=
\Drupal
::
service
(
'plugin.manager.facet
s
.facet_source'
);
$facets
=
$this
->
storage
->
loadMultiple
();
$facet_sources
=
$facet_source_plugin_manager
->
getDefinitions
();
...
...
@@ -216,11 +224,11 @@ class FacetListBuilder extends ConfigEntityListBuilder {
foreach
(
$facet_sources
as
$facet_source
)
{
$facet_source_groups
[
$facet_source
[
'id'
]]
=
[
'facet_source'
=>
$facet_source
,
'facets'
=>
[]
'facets'
=>
[]
,
];
foreach
(
$facets
as
$facet
)
{
/** @var \Drupal\
Core\Config\Entity\ConfigEntity
Interface $facet */
/** @var \Drupal\
facets\Facet
Interface $facet */
if
(
$facet
->
getFacetSourceId
()
==
$facet_source
[
'id'
])
{
$facet_source_groups
[
$facet_source
[
'id'
]][
'facets'
][
$facet
->
id
()]
=
$facet
;
// Remove this facet from $facet so it will finally only contain those
...
...
src/FacetManager/DefaultFacetManager.php
View file @
7bd666e7
This diff is collapsed.
Click to expand it.
Prev
1
2
3
4
5
6
7
8
Next