class TaxonomyColor in Fullcalendar View 8
Same name and namespace in other branches
- 8.3 src/TaxonomyColor.php \Drupal\fullcalendar_view\TaxonomyColor
- 8.2 src/TaxonomyColor.php \Drupal\fullcalendar_view\TaxonomyColor
- 6.x src/TaxonomyColor.php \Drupal\fullcalendar_view\TaxonomyColor
- 5.x src/TaxonomyColor.php \Drupal\fullcalendar_view\TaxonomyColor
Class TaxonomyColor.
Hierarchy
- class \Drupal\fullcalendar_view\TaxonomyColor uses StringTranslationTrait
Expanded class hierarchy of TaxonomyColor
1 file declares its use of TaxonomyColor
- FullCalendarDisplay.php in src/
Plugin/ views/ style/ FullCalendarDisplay.php
1 string reference to 'TaxonomyColor'
1 service uses TaxonomyColor
File
- src/
TaxonomyColor.php, line 11
Namespace
Drupal\fullcalendar_viewView source
class TaxonomyColor {
use StringTranslationTrait;
protected $entityTypeManager;
/**
* Constructor.
*/
public function __construct(EntityTypeManager $entityTypeManager) {
$this->entityTypeManager = $entityTypeManager;
}
/**
* Color input box for taxonomy terms of a vocabulary.
*/
public function colorInputBoxs($vid, array $defaultValues, $open = FALSE) {
// Taxonomy color details.
$elements = [
'#type' => 'details',
'#title' => $this
->t('Colors for Taxonomies'),
'#fieldset' => 'colors',
'#open' => $open,
'#prefix' => '<div id="color-taxonomies-div">',
'#suffix' => '</div>',
'#states' => [
// Only show this field when the 'vocabularies' is selected.
'invisible' => [
[
':input[name="style_options[vocabularies]"]' => [
'value' => '',
],
],
],
],
];
// Term IDs of the vocabulary.
$terms = $this
->getTermIds($vid);
if (isset($terms[$vid])) {
// Create a color box for each terms.
foreach ($terms[$vid] as $taxonomy) {
$color = isset($defaultValues[$taxonomy
->id()]) ? $defaultValues[$taxonomy
->id()] : '#3a87ad';
$elements[$taxonomy
->id()] = [
'#title' => $taxonomy->name->value,
'#default_value' => $color,
'#type' => 'color',
'#states' => [
// Only show this field when the 'tax_field' is selected.
'invisible' => [
[
':input[name="style_options[tax_field]"]' => [
'value' => '',
],
],
],
],
'#attributes' => [
'value' => $color,
'name' => 'style_options[color_taxonomies][' . $taxonomy
->id() . ']',
],
];
}
}
return $elements;
}
/**
* Get all terms of a vocabulary.
*/
private function getTermIds($vid) {
if (empty($vid)) {
return [];
}
$terms =& drupal_static(__FUNCTION__);
// Get taxonomy terms from database if they haven't been loaded.
if (!isset($terms[$vid])) {
// Get terms Ids.
$query = $this->entityTypeManager
->getStorage('taxonomy_term')
->getQuery();
$query
->condition('vid', $vid);
$tids = $query
->execute();
$terms[$vid] = $this->entityTypeManager
->getStorage('taxonomy_term')
->loadMultiple($tids);
}
return $terms;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
TaxonomyColor:: |
protected | property | ||
TaxonomyColor:: |
public | function | Color input box for taxonomy terms of a vocabulary. | |
TaxonomyColor:: |
private | function | Get all terms of a vocabulary. | |
TaxonomyColor:: |
public | function | Constructor. |