class IsotopeController in Isotope (with Masonry and Packery) 8
Controller routines for admin block routes.
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements ContainerInjectionInterface uses LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\isotope\Controller\IsotopeController
Expanded class hierarchy of IsotopeController
2 files declare their use of IsotopeController
- isotope.theme.inc in ./
isotope.theme.inc - Preprocessors of isotope module.
- Presentation.php in src/
Entity/ Presentation.php - Contains \Drupal\isotope\Entity\Presentation.
File
- src/
Controller/ IsotopeController.php, line 18 - Contains \Drupal\isotope\Controller\IsotopeController.
Namespace
Drupal\isotope\ControllerView source
class IsotopeController extends ControllerBase {
/**
* The transliteration service.
*
* @var \Drupal\Component\Transliteration\TransliterationInterface
*/
protected $transliteration;
/**
* The language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
public static function create(ContainerInterface $container) {
return new static($container
->get('transliteration'), $container
->get('language_manager'));
}
public function __construct(TransliterationInterface $transliteration, LanguageManagerInterface $languageManager) {
$this->transliteration = $transliteration;
$this->languageManager = $languageManager;
}
/**
* Given a layout name return the name of a library to load.
*
* @param string|array $properties
* Name of layout mode or other plugin.
*
* @return array
* Array of library names to load, keyed by property name.
*/
public static function libraryMapping($properties) {
$properties = (array) $properties;
$mappings = [
'cellsByColumn' => 'isotope/isotope-cells-by-column',
'cellsByRow' => 'isotope/isotope-cells-by-row',
'fitColumns' => 'isotope/isotope-fit-columns',
'fitRows' => 'isotope/isotope-layout',
'horiz' => 'isotope/isotope-horizontal',
'imagesloaded' => 'isotope/imagesloaded',
'masonry' => 'isotope/isotope-layout',
'masonryHorizontal' => 'isotope/isotope-masonry-horizontal',
'packery' => 'isotope/packery',
'vertical' => 'isotope/isotope-layout',
];
return array_intersect_key($mappings, array_flip($properties));
}
/**
* Convert a snake_case string to a camelCase string.
*
* @param string $raw
* String in snake_case.
*
* @return string
* String in camelCase.
*/
public static function snakeToCamel($raw) {
return lcfirst(str_replace(' ', '', ucwords(str_replace([
'-',
'_',
], ' ', $raw))));
}
/**
* Strip all special chars to make value suitable for css class name.
*
* @param string|array $raw
* The raw value to be sanitized. Arrays will be imploded by space.
*
* @return string
* The sanitized value.
*/
public function sanitize($raw) {
$safe = $raw;
// Recursively sanitize arrays.
if (is_array($raw)) {
$safe = [];
foreach ($raw as $i) {
$safe[] = $this
->sanitize($i);
}
return implode(' ', $safe);
}
// Transliterate non-latin characters.
// @TODO: Using services means stop using static.
$language_code = $this->languageManager
->getDefaultLanguage()
->getId();
$safe = $this->transliteration
->transliterate($safe, $language_code);
// Basic class-name rules.
$safe = strtolower($safe);
$safe = preg_replace('/[^a-z0-9]/s', '-', $safe);
$safe = preg_replace('/-{2,}/', '-', $safe);
return $safe;
}
/**
* Returns a demo page
*
* @TODO: This should be in an example sub-module.
*
* @return array
* A #type 'page' render array containing the block region demo.
*/
public function demo() {
$render[] = [
'#markup' => $this
->t('<p>You can explore this example for yourself at <strong>___</strong>.</p>'),
];
// The label can be anything, including images, etc. Filtering happens on the
// key.
$colors = [
'blue' => 'Blue',
'red' => '<span class="thisIsCustomisedLabel">Red</span>',
'yellow' => 'Yellow',
];
$render[] = [
'#theme' => 'isotope_filter',
'#items' => $colors,
// Optional filter_name: unique to distinguish it from the other filters on
// the page.
'#filter_name' => 'color',
// Optional filter_title: displayed as a list title.
'#filter_title' => $this
->t('Colour'),
];
$sizes = [
'small' => 'Small',
'wide' => 'Wide',
'big' => 'Big',
'tall' => 'Tall',
];
$render[] = [
'#theme' => 'isotope_filter',
'#items' => $sizes,
'#filter_name' => 'size',
'#filter_title' => $this
->t('Size'),
];
$shapes = [
'round' => 'Round',
// Transliterate non-latin characters.
'square (naïve jalapeño pâté)' => 'Square',
];
$render[] = [
'#theme' => 'isotope_filter',
'#items' => $shapes,
'#filter_name' => 'shape',
'#filter_title' => $this
->t('Shapes'),
'#instance' => 1,
];
$sorts = [
'Size' => 'size',
'shape',
'color',
[
'color',
'size',
],
'Color then Shape' => [
'color',
'shape',
],
];
$render[] = [
'#theme' => 'isotope_sorter',
'#sorts' => $sorts,
'#default_label' => $this
->t('Original'),
'#instance' => 1,
];
// Create items of every size shape and color.
$items = [];
foreach ($sizes as $size => $label1) {
foreach ($shapes as $shape => $label2) {
foreach ($colors as $color => $label3) {
$items[] = [
'value' => '<p>Item</p>',
'data' => [
'size' => $size,
'shape' => $shape,
'color' => $color,
],
];
}
}
}
$render['grid'] = [
'#theme' => 'isotope_grid',
'#items' => $items,
'#instance' => 1,
'#attached' => [
'library' => [
'isotope/isotope-example',
],
],
];
return $render;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ControllerBase:: |
protected | property | The configuration factory. | |
ControllerBase:: |
protected | property | The current user service. | 1 |
ControllerBase:: |
protected | property | The entity form builder. | |
ControllerBase:: |
protected | property | The entity manager. | |
ControllerBase:: |
protected | property | The entity type manager. | |
ControllerBase:: |
protected | property | The form builder. | 2 |
ControllerBase:: |
protected | property | The key-value storage. | 1 |
ControllerBase:: |
protected | property | The module handler. | 2 |
ControllerBase:: |
protected | property | The state service. | |
ControllerBase:: |
protected | function | Returns the requested cache bin. | |
ControllerBase:: |
protected | function | Retrieves a configuration object. | |
ControllerBase:: |
private | function | Returns the service container. | |
ControllerBase:: |
protected | function | Returns the current user. | 1 |
ControllerBase:: |
protected | function | Retrieves the entity form builder. | |
ControllerBase:: |
protected | function | Retrieves the entity manager service. | |
ControllerBase:: |
protected | function | Retrieves the entity type manager. | |
ControllerBase:: |
protected | function | Returns the form builder service. | 2 |
ControllerBase:: |
protected | function | Returns a key/value storage collection. | 1 |
ControllerBase:: |
protected | function | Returns the language manager service. | 1 |
ControllerBase:: |
protected | function | Returns the module handler. | 2 |
ControllerBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
ControllerBase:: |
protected | function | Returns the state storage service. | |
IsotopeController:: |
protected | property |
The language manager. Overrides ControllerBase:: |
|
IsotopeController:: |
protected | property | The transliteration service. | |
IsotopeController:: |
public static | function |
Instantiates a new instance of this class. Overrides ControllerBase:: |
|
IsotopeController:: |
public | function | Returns a demo page | |
IsotopeController:: |
public static | function | Given a layout name return the name of a library to load. | |
IsotopeController:: |
public | function | Strip all special chars to make value suitable for css class name. | |
IsotopeController:: |
public static | function | Convert a snake_case string to a camelCase string. | |
IsotopeController:: |
public | function | ||
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
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. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |