Skip to content
Snippets Groups Projects
Commit dd60b45b authored by Antonio De Marco's avatar Antonio De Marco
Browse files

#91: Fix libraries and start removing obsolete code.

parent b73f813a
No related branches found
No related tags found
No related merge requests found
......@@ -42,7 +42,7 @@ class PatternsLibraryController extends ControllerBase {
* Pattern label.
*/
public function title($name) {
return $this->patternsManager->getPattern($name)->getLabel();
return $this->patternsManager->getDefinition($name)->getLabel();
}
/**
......
......@@ -52,17 +52,6 @@ class PatternDefinition extends PluginDefinition implements DerivablePluginDefin
$this->setThemeHook(self::PATTERN_PREFIX . $this->id());
$this->setCustomThemeHook(FALSE);
}
// Process libraries.
foreach ($this->getLibraries() as $library) {
if (is_array($library)) {
$libraries[] = self::LIBRARY_PREFIX . '/' . $this->id() . '.' . key($library);
}
else {
$libraries[] = $library;
}
$this->setLibraries($libraries);
}
}
/**
......@@ -434,6 +423,25 @@ class PatternDefinition extends PluginDefinition implements DerivablePluginDefin
return $this->libraries;
}
/**
* Getter.
*
* @return mixed
* Property value.
*/
public function getLibrariesNames() {
$libraries = [];
foreach ($this->getLibraries() as $library) {
if (is_array($library)) {
$libraries[] = self::LIBRARY_PREFIX . '/' . $this->id() . '.' . key($library);
}
else {
$libraries[] = $library;
}
}
return $libraries;
}
/**
* Setter.
*
......
......@@ -65,7 +65,7 @@ class Pattern extends RenderElement {
* Render array.
*/
public static function processLibraries(array $element) {
foreach (UiPatterns::getPatternDefinition($element['#id'])->getLibraries() as $library) {
foreach (UiPatterns::getPatternDefinition($element['#id'])->getLibrariesNames() as $library) {
$element['#attached']['library'][] = $library;
}
......
......@@ -2,6 +2,7 @@
namespace Drupal\ui_patterns;
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
......@@ -11,7 +12,7 @@ use Drupal\Core\Plugin\DefaultPluginManager;
/**
* Provides the default ui_patterns manager.
*/
class UiPatternsManager extends DefaultPluginManager implements UiPatternsManagerInterface {
class UiPatternsManager extends DefaultPluginManager implements PluginManagerInterface {
use StringTranslationTrait;
......
<?php
namespace Drupal\ui_patterns;
use Drupal\Component\Plugin\PluginManagerInterface;
/**
* Defines an interface for ui_patterns managers.
*/
interface UiPatternsManagerInterface extends PluginManagerInterface {
/**
* Get a fully instantiated pattern object.
*
* @param string $id
* Pattern ID.
*
* @return \Drupal\ui_patterns\UiPatternBase
* Pattern object instance.
*/
public function getPattern($id);
/**
* Get a fully instantiated list of pattern objects.
*
* @return \Drupal\ui_patterns\UiPatternInterface[]
* List of pattern object instances.
*/
public function getPatterns();
/**
* Return list of available patterns to be used as select options.
*
* @return array
* List of available patterns.
*/
public function getPatternsOptions();
/**
* Check whereas the given theme hook is an actual pattern hook.
*
* @param string $hook
* Theme hook.
*
* @return bool
* Whereas the given theme hook is an actual pattern hook.
*/
public function isPatternHook($hook);
}
......@@ -11,7 +11,7 @@ use Drupal\ui_patterns\UiPatterns;
* Implements hook_theme().
*/
function ui_patterns_theme() {
/** @var \Drupal\ui_patterns\UiPatternInterface $pattern */
/** @var \Drupal\ui_patterns\UiPatternBase $pattern */
$items = [
'patterns_destination' => [
'variables' => ['sources' => NULL, 'context' => NULL],
......@@ -31,7 +31,7 @@ function ui_patterns_theme() {
* Implements hook_library_info_build()
*/
function ui_patterns_library_info_build() {
/** @var \Drupal\ui_patterns\UiPatternInterface $pattern */
/** @var \Drupal\ui_patterns\UiPatternBase $pattern */
$definitions = [];
foreach (UiPatterns::getManager()->getPatterns() as $pattern) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment