class MixitupFunc in MixItUp Views 8
Same name and namespace in other branches
- 8.2 src/MixitupFunc.php \Drupal\mixitup_views\MixitupFunc
Performs assistance functionality.
@package Drupal\mixitup_views
Hierarchy
- class \Drupal\mixitup_views\MixitupFunc
Expanded class hierarchy of MixitupFunc
3 files declare their use of MixitupFunc
- MixitupFiltersForm.php in src/
Form/ MixitupFiltersForm.php - MixitUpFiltersFormTest.php in tests/
src/ Kernel/ MixitUpFiltersFormTest.php - MixItUpFuncTest.php in tests/
src/ Kernel/ MixItUpFuncTest.php
1 string reference to 'MixitupFunc'
1 service uses MixitupFunc
File
- src/
MixitupFunc.php, line 14
Namespace
Drupal\mixitup_viewsView source
class MixitupFunc {
/**
* Static array for store active nodes terms.
*
* @var array
*/
protected static $populatedFilters = [];
/**
* Static array for store information about which nodes have a specific tid.
*
* @var array
*/
protected static $nodeFilters = [];
/**
* Default options service.
*
* @var null
*/
protected $defaultOptionsService;
/**
* EntityTypeManager service.
*
* @var object
*/
protected $entityTypeManager;
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $connection;
/**
* Constructor.
*
* @param \Drupal\mixitup_views\MixitupViewsDefaultOptionsService $defaultOptionsService
* MixitupViewsDefaultOptionsService service.
* @param \Drupal\Core\Entity\EntityTypeManager $entityTypeManagerService
* EntityTypeManager service.
* @param \Drupal\Core\Database\Connection $connection
* The database connection.
*/
public function __construct(MixitupViewsDefaultOptionsService $defaultOptionsService, EntityTypeManager $entityTypeManagerService, Connection $connection) {
$this->defaultOptionsService = $defaultOptionsService;
$this->entityTypeManager = $entityTypeManagerService;
$this->connection = $connection;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('mixitup_views.default_options_service'), $container
->get('entity_type.manager'), $container
->get('database'));
}
/**
* Get classes string for node.
*
* @param int $nid
* Node id.
*
* @return string
* Classes string.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
public function getRowClasses($nid) {
$tids = $this
->getNodeTids($nid);
$classes = [];
if (!empty($tids)) {
foreach ($tids as $tid) {
$classes[] = 'tid_' . $tid;
$this
->populateFilters($tid, $nid);
}
}
$classes = implode(' ', $classes);
return $classes;
}
/**
* Get all node's taxonomy ids.
*
* @param int $nid
* Node id.
*
* @return array
* Array of tids.
*/
public function getNodeTids($nid) {
$tids = $this->connection
->select('taxonomy_index', 'ti')
->fields('ti', [
'tid',
'nid',
])
->condition('ti.nid', $nid)
->execute()
->fetchAllKeyed();
return array_keys($tids);
}
/**
* Populates structured array of used taxonomy terms.
*
* @param int $tid
* Taxonomy id.
* @param int $nid
* Node id.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
public function populateFilters($tid, $nid) {
$term = $this->entityTypeManager
->getStorage('taxonomy_term')
->load($tid);
/* @var \Drupal\taxonomy\Entity\Term $term */
if (!empty($term)) {
$vid = $term
->bundle();
self::$populatedFilters[$vid]['.tid_' . $tid] = $term
->getName();
$this
->populateNodeFilters($nid, $tid);
}
}
/**
* Collects information regarding wich nodes have a specific tid.
*
* @param int $nid
* Node id.
* @param int $tid
* Taxonomy id.
*/
public function populateNodeFilters($nid, $tid) {
self::$nodeFilters[$tid][] = $nid;
}
/**
* Gets populated filters.
*
* @return array
* Array with structure item[vid]['tid_{tid}'] = term_name.
*/
public function getPopulatedFilters() {
return self::$populatedFilters;
}
/**
* Gets populated node filters.
*
* @return array
* Array with structure item[tid] => array(nids).
*/
public function getPopulatedNodeFilters() {
return self::$nodeFilters;
}
/**
* Get default mixitup options.
*
* @param bool $convert
* Convert check.
*
* @return mixed
* Array of default options.
*/
public function getDefaultOptions($convert = NULL) {
return $this->defaultOptionsService
->defaultOptions($convert);
}
/**
* Checks is mixitup js file exists.
*
* @return bool
* True or False.
*/
public function isMixitupInstalled() {
if (is_file('libraries/mixitup/dist/mixitup.min.js')) {
return TRUE;
}
return FALSE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MixitupFunc:: |
protected | property | The database connection. | |
MixitupFunc:: |
protected | property | Default options service. | |
MixitupFunc:: |
protected | property | EntityTypeManager service. | |
MixitupFunc:: |
protected static | property | Static array for store information about which nodes have a specific tid. | |
MixitupFunc:: |
protected static | property | Static array for store active nodes terms. | |
MixitupFunc:: |
public static | function | ||
MixitupFunc:: |
public | function | Get default mixitup options. | |
MixitupFunc:: |
public | function | Get all node's taxonomy ids. | |
MixitupFunc:: |
public | function | Gets populated filters. | |
MixitupFunc:: |
public | function | Gets populated node filters. | |
MixitupFunc:: |
public | function | Get classes string for node. | |
MixitupFunc:: |
public | function | Checks is mixitup js file exists. | |
MixitupFunc:: |
public | function | Populates structured array of used taxonomy terms. | |
MixitupFunc:: |
public | function | Collects information regarding wich nodes have a specific tid. | |
MixitupFunc:: |
public | function | Constructor. |