Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update plugin system by using the PluginBase from D8 #5

Merged
merged 5 commits into from Jun 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -20,7 +20,7 @@ class BlockController extends BaseRecursionController {
*/
protected function isCacheable(array $default_cache_info, array $context) {
// Disabled caching for now.
return variable_get('render_cache_' . $this->getType() . '_' . $context['region'] . '_enabled', TRUE)
return variable_get('render_cache_' . $this->getPluginId() . '_' . $context['region'] . '_enabled', TRUE)
&& parent::isCacheable($default_cache_info, $context);
}

Expand Down
Expand Up @@ -18,7 +18,7 @@ class EntityController extends BaseRecursionController {
* {@inheritdoc}
*/
protected function isCacheable(array $default_cache_info, array $context) {
return variable_get('render_cache_' . $this->getType() . '_' . $context['entity_type'] . '_enabled', TRUE)
return variable_get('render_cache_' . $this->getPluginId() . '_' . $context['entity_type'] . '_enabled', TRUE)
&& parent::isCacheable($default_cache_info, $context);
}

Expand Down
Expand Up @@ -64,7 +64,7 @@ protected function getDefaultCacheInfo($context) {
*/
protected function isCacheable(array $default_cache_info, array $context) {
// Disabled caching for now.
return variable_get('render_cache_' . $this->getType() . '_' . $context['page_callback'] . '_enabled', FALSE)
return variable_get('render_cache_' . $this->getPluginId() . '_' . $context['page_callback'] . '_enabled', FALSE)
&& parent::isCacheable($default_cache_info, $context);
}

Expand Down
3 changes: 0 additions & 3 deletions src/Cache/RenderCacheBackendAdapter.php
Expand Up @@ -7,11 +7,8 @@
namespace Drupal\render_cache\Cache;

use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Render\Element;

use Drupal\render_cache\Cache\RenderStackInterface;
use DrupalCacheInterface;
use RenderCache;

/**
Expand Down
1 change: 0 additions & 1 deletion src/Cache/RenderStack.php
Expand Up @@ -10,7 +10,6 @@
use Drupal\Core\Cache\CacheableInterface;
use Drupal\Core\Render\Element;

use Drupal\render_cache\Cache\Cache;
use RenderCache;

/**
Expand Down
53 changes: 0 additions & 53 deletions src/Plugin/BasePlugin.php

This file was deleted.

30 changes: 0 additions & 30 deletions src/Plugin/PluginInterface.php

This file was deleted.

4 changes: 2 additions & 2 deletions src/RenderCache/Controller/AbstractBaseController.php
Expand Up @@ -6,14 +6,14 @@

namespace Drupal\render_cache\RenderCache\Controller;

use Drupal\render_cache\Plugin\BasePlugin;
use Drupal\Component\Plugin\PluginBase;

/**
* Controller abstract base class.
*
* @ingroup rendercache
*/
abstract class AbstractBaseController extends BasePlugin implements ControllerInterface {
abstract class AbstractBaseController extends PluginBase implements ControllerInterface {
// -----------------------------------------------------------------------
// Suggested implementation functions.

Expand Down
27 changes: 15 additions & 12 deletions src/RenderCache/Controller/BaseController.php
Expand Up @@ -9,7 +9,6 @@
use Drupal\render_cache\Cache\Cache;
use Drupal\render_cache\Cache\RenderCacheBackendAdapterInterface;
use Drupal\render_cache\Cache\RenderCachePlaceholder;
use Drupal\render_cache\Cache\RenderStack;
use Drupal\render_cache\Cache\RenderStackInterface;

use RenderCache;
Expand Down Expand Up @@ -45,15 +44,19 @@ abstract class BaseController extends AbstractBaseController {
/**
* Constructs a controller plugin object.
*
* @param array $plugin
* The plugin definition.
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\render_cache\Cache\RenderStack $render_stack
* The render stack.
* @param \Drupal\render_cache\Cache\RenderCacheBackendAdapter $cache
* The cache backend adapter.
*/
public function __construct(array $plugin, RenderStackInterface $render_stack, RenderCacheBackendAdapterInterface $cache) {
parent::__construct($plugin);
public function __construct(array $configuration, $plugin_id, $plugin_definition, RenderStackInterface $render_stack, RenderCacheBackendAdapterInterface $cache) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->renderStack = $render_stack;
$this->cache = $cache;
}
Expand Down Expand Up @@ -140,7 +143,7 @@ public function view(array $objects) {
// @todo Use a #post_render function.
if (isset($render['#markup'])
&& (variable_get('render_cache_debug_output', FALSE)
|| variable_get('render_cache_debug_output_' . $this->getType(), FALSE)
|| variable_get('render_cache_debug_output_' . $this->getPluginId(), FALSE)
|| !empty($cache_info['render_cache_debug_output']))
) {
// @todo Move to helper function.
Expand All @@ -156,7 +159,7 @@ public function view(array $objects) {
$attached = print_r($storage, TRUE);
$prefix .= "\nATTACHED: " . print_r($full_storage, TRUE) . "\n";
$prefix .= "\nHOOKS:\n";
$hook_prefix = 'render_cache_' . $this->getType() . '_';
$hook_prefix = 'render_cache_' . $this->getPluginId() . '_';
foreach (array('default_cache_info', 'cache_info', 'keys', 'tags', 'hash', 'validate') as $hook) {
$prefix .= '* hook_' . $hook_prefix . $hook . "_alter()\n";
}
Expand Down Expand Up @@ -193,7 +196,7 @@ protected function isCacheable(array $default_cache_info, array $context) {
$ignore_request_method_check = $default_cache_info['render_cache_ignore_request_method_check'];
return isset($default_cache_info['granularity'])
&& variable_get('render_cache_enabled', TRUE)
&& variable_get('render_cache_' . $this->getType() . '_enabled', TRUE)
&& variable_get('render_cache_' . $this->getPluginId() . '_enabled', TRUE)
&& render_cache_call_is_cacheable(NULL, $ignore_request_method_check);
}

Expand All @@ -217,7 +220,7 @@ protected function getCacheInfo($object, array $context) {
protected function getCacheKeys($object, array $context) {
return array(
'render_cache',
$this->getType(),
$this->getPluginId(),
);
}

Expand All @@ -236,7 +239,7 @@ protected function getCacheHash($object, array $context) {
protected function getCacheTags($object, array $context) {
return array(
'rendered',
$this->getType() . '_view',
$this->getPluginId() . '_view',
);
}

Expand Down Expand Up @@ -480,7 +483,7 @@ protected function renderRecursive(array $objects) {
* {@inheritdoc}
*/
protected function alter($type, &$data, &$context1 = NULL, &$context2 = NULL, &$context3 = NULL) {
drupal_alter('render_cache_' . $this->getType() . '_' . $type, $data, $context1, $context2, $context3);
drupal_alter('render_cache_' . $this->getPluginId() . '_' . $type, $data, $context1, $context2, $context3);
}

/**
Expand All @@ -506,7 +509,7 @@ protected function getPlaceholders(array $objects, array $cache_info_map, $conte
// @todo Serialize the object.
$ph_object = array(
'id' => $id,
'type' => $this->getType(),
'type' => $this->getPluginId(),
'context' => $context,
'object' => $objects[$id],
'cache_info' => $cache_info,
Expand Down
5 changes: 2 additions & 3 deletions src/RenderCache/RenderStrategy/BaseRenderStrategy.php
Expand Up @@ -5,14 +5,13 @@
*/

namespace Drupal\render_cache\RenderCache\RenderStrategy;

use Drupal\render_cache\Plugin\BasePlugin;
use Drupal\Component\Plugin\PluginBase;

/**
* Base class for RenderStrategy plugin objects.
*
* @ingroup rendercache
*/
abstract class BaseRenderStrategy extends BasePlugin implements RenderStrategyInterface {
abstract class BaseRenderStrategy extends PluginBase implements RenderStrategyInterface {

}
4 changes: 2 additions & 2 deletions src/RenderCache/ValidationStrategy/BaseValidationStrategy.php
Expand Up @@ -6,12 +6,12 @@

namespace Drupal\render_cache\RenderCache\ValidationStrategy;

use Drupal\render_cache\Plugin\BasePlugin;
use Drupal\Component\Plugin\PluginBase;

/**
* Base class for ValidationStrategy plugin objects.
*
* @ingroup rendercache
*/
abstract class BaseValidationStrategy extends BasePlugin implements ValidationStrategyInterface {
abstract class BaseValidationStrategy extends PluginBase implements ValidationStrategyInterface {
}
Expand Up @@ -81,28 +81,7 @@ public function getContainerDefinition() {
),
);

// Plugin Managers - filled out by alterDefinition() of service_container
// module.
// This needs to exist in an empty state.
$services['render_cache.controller'] = array();
$services['render_cache.render_strategy'] = array();
$services['render_cache.validation_strategy'] = array();

// Syntax is: <service_name> => <plugin_manager_definition>
$parameters['service_container.plugin_managers']['ctools'] = array(
'render_cache.controller' => array(
'owner' => 'render_cache',
'type' => 'Controller',
),
'render_cache.validation_strategy' => array(
'owner' => 'render_cache',
'type' => 'ValidationStrategy',
),
'render_cache.render_strategy' => array(
'owner' => 'render_cache',
'type' => 'RenderStrategy',
),
);
$parameters['ctools_plugins_auto_discovery.render_cache'] = array('render_cache');

return array(
'parameters' => $parameters,
Expand Down
3 changes: 2 additions & 1 deletion tests/composer.json
@@ -1,7 +1,8 @@
{
"require-dev": {
"phpunit/phpunit": "3.7.*",
"mockery/mockery": "0.9.*"
"mockery/mockery": "0.9.*",
"lionsad/service_container": "dev-7.x-1.x"
},
"autoload": {
"psr-0": {
Expand Down
43 changes: 0 additions & 43 deletions tests/src/Plugin/BasePluginTest.php

This file was deleted.