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

#91: Add methods to interface and remove obsolete manager method.

parent edf7e6ec
No related branches found
No related tags found
No related merge requests found
......@@ -9,4 +9,24 @@ namespace Drupal\ui_patterns\Plugin;
*/
interface PatternInterface {
/**
* Get theme implementation for current pattern.
*
* @see ui_patterns_theme()
*
* @return array
* Theme implementation array.
*/
public function getThemeImplementation();
/**
* Get library definitions for current pattern.
*
* @see ui_patterns_library_info_build()
*
* @return array
* Library definitions array.
*/
public function getLibraryDefinitions();
}
......@@ -37,20 +37,6 @@ class UiPatternsManager extends DefaultPluginManager implements PluginManagerInt
$this->setCacheBackend($cache_backend, 'ui_patterns', ['ui_patterns']);
}
/**
* Get pattern object.
*
* @param string $id
* Pattern ID.
*
* @return \Drupal\ui_patterns\Plugin\PatternBase
* Pattern object.
*/
public function getPattern($id) {
// @todo should we statically cache this?
return $this->getFactory()->createInstance($id);
}
/**
* Get pattern objects.
*
......@@ -58,10 +44,9 @@ class UiPatternsManager extends DefaultPluginManager implements PluginManagerInt
* Pattern objects.
*/
public function getPatterns() {
// @todo should we statically cache this?
$patterns = [];
foreach ($this->getDefinitions() as $definition) {
$patterns[] = $this->getPattern($definition->id());
$patterns[] = $this->getFactory()->createInstance($definition->id());
}
return $patterns;
}
......
......@@ -20,10 +20,10 @@ class UiPatternsManagerTest extends AbstractUiPatternsTest {
*/
public function testGetPattern() {
$manager = UiPatterns::getManager();
$definitions = $manager->getDefinitions();
foreach ($manager->getDefinitions() as $definition) {
$pattern = $manager->getPattern($definition->id());
assert($pattern->getBaseId(), equals($definition->id()));
foreach ($manager->getPatterns() as $pattern) {
assert($pattern->getBaseId(), equals($definitions[$pattern->getPluginId()]->id()));
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment