class FacetapiDependencyBundle in Facet API 6.3
Same name and namespace in other branches
- 7.2 plugins/facetapi/dependency_bundle.inc \FacetapiDependencyBundle
- 7 plugins/facetapi/dependency_bundle.inc \FacetapiDependencyBundle
Adds a dependency on bundle.
Hierarchy
- class \FacetapiDependency
- class \FacetapiDependencyBundle
Expanded class hierarchy of FacetapiDependencyBundle
2 string references to 'FacetapiDependencyBundle'
- facetapi_facetapi_dependencies in ./
facetapi.facetapi.inc - Implements hook_facetapi_dependencies().
- hook_facetapi_dependencies in ./
facetapi.api.php - Define all dependency plugins provided by the module.
File
- plugins/
facetapi/ dependency_bundle.inc, line 11 - Performs a dependency check against the passed bundle.
View source
class FacetapiDependencyBundle extends FacetapiDependency {
/**
* Executes the dependency check.
*/
public function execute() {
switch ($this->settings['bundle']) {
case 'referenced':
// Check match between the field's bundles and active bundle items.
foreach ($this
->getEnabledBundleFacets() as $facet) {
foreach ($this->activeItems[$facet['name']] as $entity => $facet) {
$field_info = content_fields($this->facet['field api name'], $entity);
if ($field_info) {
return NULL;
}
}
}
// There was no match.
return FALSE;
case 'selected':
// Check match between selected bundles and active bundle items.
$selected = array_filter($this->settings['bundle_selected']);
foreach ($this
->getEnabledBundleFacets() as $facet) {
if (array_intersect_key($this->activeItems[$facet['name']], $selected)) {
return NULL;
}
}
// There was no match.
return FALSE;
}
}
/**
* Returns an array of enabled facets that filter by bundle.
*
* @return array
* An array of enabled bundle facets.
*/
public function getEnabledBundleFacets() {
$enabled = array_filter($this->adapter
->getEnabledFacets(), array(
$this,
'filterBundleFacets',
));
$active = array_filter($this->activeItems);
return array_intersect_key($enabled, $active);
}
/**
* Returns TRUE if the facet contains bundle information.
*
* @param array $facet
* The facet definition beinf filtered.
*
* @return
* A boolean flagging whether the item should remain in the array.
*/
public function filterBundleFacets($facet) {
return !empty($facet['field api bundles']);
}
/**
* Adds dependency settings to the form.
*/
public function settingsForm(&$form, &$form_state) {
// Builds array of options.
$options = array();
$options['none'] = t('No dependencies.');
if ($this->facet['field api name']) {
$options['referenced'] = t('A bundle this field is attached to must be active.');
}
$options['selected'] = t('At least one of the selected bundles must be active.');
$form[$this->id]['bundle'] = array(
'#title' => t('Dependency settings'),
'#type' => 'radios',
'#options' => $options,
'#default_value' => $this->settings['bundle'],
);
$form[$this->id]['bundle_selected'] = array(
'#title' => t('Required bundles'),
'#type' => 'checkboxes',
'#options' => $this
->getBundleOptions($form['#facetapi']['adapter']
->getTypes()),
'#default_value' => $this->settings['bundle_selected'],
'#states' => array(
'visible' => array(
'input[name="bundle"]' => array(
'value' => 'selected',
),
),
),
'#description' => t('At least one of the selected bundles must be active for this facet to be rendered.'),
);
}
/**
* Gets bundles.
*
* @param array $entity_types
* An array containing the machine readable name of the entities.
*
* @return
* An array of bundles associates with the entities.
*/
public function getBundleOptions(array $entity_types) {
$options = array();
// No entities in D6 - Only nodes
$bundle_types = node_get_types();
foreach ($bundle_types as $bundle => $bundle_info) {
$options[$bundle] = check_plain($bundle_info->name);
}
return $options;
}
/**
* Returns defaults for settings.
*/
public function getDefaultSettings() {
return array(
'bundle' => 'none',
'bundle_selected' => array(),
);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FacetapiDependency:: |
protected | property | An array of active items. | |
FacetapiDependency:: |
protected | property | The adapter object. | |
FacetapiDependency:: |
protected | property | The facet definition. | |
FacetapiDependency:: |
protected | property | An array of facet settings. | |
FacetapiDependency:: |
public | function | Gets the facet definition. | |
FacetapiDependency:: |
public | function | Gets the id of the plugin. | |
FacetapiDependency:: |
public | function | ||
FacetapiDependencyBundle:: |
public | function |
Executes the dependency check. Overrides FacetapiDependency:: |
|
FacetapiDependencyBundle:: |
public | function | Returns TRUE if the facet contains bundle information. | |
FacetapiDependencyBundle:: |
public | function | Gets bundles. | |
FacetapiDependencyBundle:: |
public | function |
Returns defaults for settings. Overrides FacetapiDependency:: |
|
FacetapiDependencyBundle:: |
public | function | Returns an array of enabled facets that filter by bundle. | |
FacetapiDependencyBundle:: |
public | function |
Adds dependency settings to the form. Overrides FacetapiDependency:: |