Commit c435ef8d authored by alexpott's avatar alexpott

Issue #2062573 by claudiu.cristea, tim.plunkett, Xano: Change notice: Add...

Issue #2062573 by claudiu.cristea, tim.plunkett, Xano: Change notice: Add method defaultConfiguration() in ConfigurablePluginInterface.
parent 935013e9
......@@ -28,4 +28,12 @@ public function getConfiguration();
*/
public function setConfiguration(array $configuration);
/**
* Returns default configuration for this plugin.
*
* @return array
* An associative array with the default configuration.
*/
public function defaultConfiguration();
}
......@@ -22,15 +22,13 @@ abstract class ConfigurableActionBase extends ActionBase implements Configurable
public function __construct(array $configuration, $plugin_id, array $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->configuration += $this->getDefaultConfiguration();
$this->configuration += $this->defaultConfiguration();
}
/**
* Returns default configuration for this action.
*
* @return array
* {@inheritdoc}
*/
protected function getDefaultConfiguration() {
public function defaultConfiguration() {
return array();
}
......
......@@ -105,7 +105,7 @@ public function execute($entity = NULL) {
/**
* {@inheritdoc}
*/
protected function getDefaultConfiguration() {
public function defaultConfiguration() {
return array(
'recipient' => '',
'subject' => '',
......
......@@ -87,7 +87,7 @@ public function execute($object = NULL) {
/**
* {@inheritdoc}
*/
protected function getDefaultConfiguration() {
public function defaultConfiguration() {
return array(
'url' => '',
);
......
......@@ -61,7 +61,7 @@ public function execute($entity = NULL) {
/**
* {@inheritdoc}
*/
protected function getDefaultConfiguration() {
public function defaultConfiguration() {
return array(
'message' => '',
);
......
......@@ -16,6 +16,13 @@
*/
abstract class AggregatorPluginSettingsBase extends PluginBase implements PluginFormInterface, ConfigurablePluginInterface {
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return array();
}
/**
* {@inheritdoc}
*/
......
......@@ -23,9 +23,9 @@
class AggregatorCategoryBlock extends BlockBase {
/**
* Overrides \Drupal\block\BlockBase::settings().
* {@inheritdoc}
*/
public function settings() {
public function defaultConfiguration() {
// By default, the block will contain 10 feed items.
return array(
'block_count' => 10,
......
......@@ -23,9 +23,9 @@
class AggregatorFeedBlock extends BlockBase {
/**
* Overrides \Drupal\block\BlockBase::settings().
* {@inheritdoc}
*/
public function settings() {
public function defaultConfiguration() {
// By default, the block will contain 10 feed items.
return array(
'block_count' => 10,
......
......@@ -75,9 +75,9 @@ public static function create(ContainerInterface $container, array $configuratio
}
/**
* Overrides \Drupal\block\BlockBase::settings().
* {@inheritdoc}
*/
public function settings() {
public function defaultConfiguration() {
return array(
'status' => TRUE,
'info' => '',
......
......@@ -27,7 +27,7 @@ abstract class BlockBase extends PluginBase implements BlockPluginInterface {
public function __construct(array $configuration, $plugin_id, array $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->configuration += $this->settings() + array(
$this->configuration += $this->defaultConfiguration() + array(
'label' => '',
'module' => $plugin_definition['module'],
'label_display' => BlockInterface::BLOCK_LABEL_VISIBLE,
......@@ -35,22 +35,6 @@ public function __construct(array $configuration, $plugin_id, array $plugin_defi
);
}
/**
* Returns plugin-specific settings for the block.
*
* Block plugins only need to override this method if they override the
* defaults provided in BlockBase::settings().
*
* @return array
* An array of block-specific settings to override the defaults provided in
* BlockBase::settings().
*
* @see \Drupal\block\BlockBase::settings().
*/
public function settings() {
return array();
}
/**
* {@inheritdoc}
*/
......@@ -65,6 +49,13 @@ public function setConfiguration(array $configuration) {
$this->configuration = $configuration;
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return array();
}
/**
* {@inheritdoc}
*/
......
......@@ -21,18 +21,6 @@
*/
interface BlockPluginInterface extends ConfigurablePluginInterface, PluginFormInterface, PluginInspectionInterface {
/**
* Returns the default settings for this block plugin.
*
* @return array
* An associative array of block settings for this block, keyed by the
* setting name.
*
* @todo Consider merging this with the general plugin configuration member
* variable and its getter/setter in http://drupal.org/node/1764380.
*/
public function settings();
/**
* Indicates whether the block should be shown.
*
......
......@@ -69,7 +69,7 @@ protected function defineOptions() {
* An array of block-specific settings to override the defaults provided in
* \Drupal\views\Plugin\Block\ViewsBlock::settings().
*
* @see \Drupal\views\Plugin\Block\ViewsBlock::settings().
* @see \Drupal\views\Plugin\Block\ViewsBlock::defaultConfiguration()
*/
public function blockSettings(array $settings) {
$settings['items_per_page'] = 'none';
......
......@@ -24,7 +24,7 @@ class TestBlockInstantiation extends BlockBase {
/**
* {@inheritdoc}
*/
public function settings() {
public function defaultConfiguration() {
return array(
'display_message' => 'no message set',
);
......
......@@ -22,11 +22,11 @@
class TestCacheBlock extends BlockBase {
/**
* Overrides \Drupal\block\BlockBase::settings().
* {@inheritdoc}
*
* Sets a different caching strategy for testing purposes.
*/
public function settings() {
public function defaultConfiguration() {
return array(
'cache' => DRUPAL_CACHE_PER_ROLE,
);
......
......@@ -20,11 +20,11 @@
class TestXSSTitleBlock extends TestCacheBlock {
/**
* Overrides \Drupal\block\BlockBase::settings().
* {@inheritdoc}
*
* Sets a different caching strategy for testing purposes.
*/
public function settings() {
public function defaultConfiguration() {
return array(
'cache' => DRUPAL_NO_CACHE,
);
......
......@@ -22,9 +22,9 @@
class BookNavigationBlock extends BlockBase {
/**
* Overrides \Drupal\block\BlockBase::settings().
* {@inheritdoc}
*/
public function settings() {
public function defaultConfiguration() {
return array(
'cache' => DRUPAL_CACHE_PER_PAGE | DRUPAL_CACHE_PER_ROLE,
'block_mode' => "all pages",
......
......@@ -40,7 +40,7 @@ public function execute($comment = NULL) {
/**
* {@inheritdoc}
*/
protected function getDefaultConfiguration() {
public function defaultConfiguration() {
return array(
'keywords' => array(),
);
......
......@@ -22,9 +22,9 @@
class RecentCommentsBlock extends BlockBase {
/**
* Overrides \Drupal\block\BlockBase::settings().
* {@inheritdoc}
*/
public function settings() {
public function defaultConfiguration() {
return array(
'block_count' => 10,
);
......
......@@ -106,6 +106,13 @@ public function getConfiguration() {
);
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return array();
}
/**
* {@inheritdoc}
*/
......
......@@ -15,9 +15,9 @@
abstract class ForumBlockBase extends BlockBase {
/**
* Overrides \Drupal\block\BlockBase::settings().
* {@inheritdoc}
*/
public function settings() {
public function defaultConfiguration() {
return array(
'cache' => DRUPAL_CACHE_CUSTOM,
'properties' => array(
......
......@@ -103,10 +103,17 @@ public function setConfiguration(array $configuration) {
'uuid' => '',
'weight' => '',
);
$this->configuration = $configuration['data'];
$this->configuration = $configuration['data'] + $this->defaultConfiguration();
$this->uuid = $configuration['uuid'];
$this->weight = $configuration['weight'];
return $this;
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return array();
}
}
......@@ -26,11 +26,6 @@ class CropImageEffect extends ResizeImageEffect {
* {@inheritdoc}
*/
public function applyEffect(ImageInterface $image) {
// Set sane default values.
$this->configuration += array(
'anchor' => 'center-center',
);
list($x, $y) = explode('-', $this->configuration['anchor']);
$x = image_filter_keyword($x, $image->getWidth(), $this->configuration['width']);
$y = image_filter_keyword($y, $image->getHeight(), $this->configuration['height']);
......@@ -54,12 +49,16 @@ public function getSummary() {
/**
* {@inheritdoc}
*/
public function getForm() {
$this->configuration += array(
'width' => '',
'height' => '',
public function defaultConfiguration() {
return parent::defaultConfiguration() + array(
'anchor' => 'center-center',
);
}
/**
* {@inheritdoc}
*/
public function getForm() {
$form = parent::getForm();
$form['anchor'] = array(
'#type' => 'radios',
......
......@@ -54,6 +54,16 @@ public function getSummary() {
);
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return array(
'width' => NULL,
'height' => NULL,
);
}
/**
* {@inheritdoc}
*/
......@@ -61,7 +71,7 @@ public function getForm() {
$form['width'] = array(
'#type' => 'number',
'#title' => t('Width'),
'#default_value' => isset($this->configuration['width']) ? $this->configuration['width'] : '',
'#default_value' => $this->configuration['width'],
'#field_suffix' => ' ' . t('pixels'),
'#required' => TRUE,
'#min' => 1,
......@@ -69,7 +79,7 @@ public function getForm() {
$form['height'] = array(
'#type' => 'number',
'#title' => t('Height'),
'#default_value' => isset($this->configuration['height']) ? $this->configuration['height'] : '',
'#default_value' => $this->configuration['height'],
'#field_suffix' => ' ' . t('pixels'),
'#required' => TRUE,
'#min' => 1,
......
......@@ -28,13 +28,6 @@ class RotateImageEffect extends ImageEffectBase implements ConfigurableImageEffe
* {@inheritdoc}
*/
public function applyEffect(ImageInterface $image) {
// Set sane default values.
$this->configuration += array(
'degrees' => 0,
'bgcolor' => NULL,
'random' => FALSE,
);
// Convert short #FFF syntax to full #FFFFFF syntax.
if (strlen($this->configuration['bgcolor']) == 4) {
$c = $this->configuration['bgcolor'];
......@@ -89,13 +82,24 @@ public function getSummary() {
);
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return array(
'degrees' => 0,
'bgcolor' => NULL,
'random' => FALSE,
);
}
/**
* {@inheritdoc}
*/
public function getForm() {
$form['degrees'] = array(
'#type' => 'number',
'#default_value' => (isset($this->configuration['degrees'])) ? $this->configuration['degrees'] : 0,
'#default_value' => $this->configuration['degrees'],
'#title' => t('Rotation angle'),
'#description' => t('The number of degrees the image should be rotated. Positive numbers are clockwise, negative are counter-clockwise.'),
'#field_suffix' => '°',
......@@ -103,7 +107,7 @@ public function getForm() {
);
$form['bgcolor'] = array(
'#type' => 'textfield',
'#default_value' => (isset($this->configuration['bgcolor'])) ? $this->configuration['bgcolor'] : '#FFFFFF',
'#default_value' => $this->configuration['bgcolor'],
'#title' => t('Background color'),
'#description' => t('The background color to use for exposed areas of the image. Use web-style hex colors (#FFFFFF for white, #000000 for black). Leave blank for transparency on image types that support it.'),
'#size' => 7,
......@@ -112,7 +116,7 @@ public function getForm() {
);
$form['random'] = array(
'#type' => 'checkbox',
'#default_value' => (isset($this->configuration['random'])) ? $this->configuration['random'] : 0,
'#default_value' => $this->configuration['random'],
'#title' => t('Randomize'),
'#description' => t('Randomize the rotation angle for each image. The angle specified above is used as a maximum.'),
);
......
......@@ -27,13 +27,6 @@ class ScaleImageEffect extends ResizeImageEffect {
* {@inheritdoc}
*/
public function applyEffect(ImageInterface $image) {
// Set sane default values.
$this->configuration += array(
'width' => NULL,
'height' => NULL,
'upscale' => FALSE,
);
if (!$image->scale($this->configuration['width'], $this->configuration['height'], $this->configuration['upscale'])) {
watchdog('image', 'Image scale failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->getToolkitId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()), WATCHDOG_ERROR);
return FALSE;
......@@ -60,6 +53,15 @@ public function getSummary() {
);
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return parent::defaultConfiguration() + array(
'upscale' => FALSE,
);
}
/**
* {@inheritdoc}
*/
......@@ -70,7 +72,7 @@ public function getForm() {
$form['height']['#required'] = FALSE;
$form['upscale'] = array(
'#type' => 'checkbox',
'#default_value' => (isset($this->configuration['upscale'])) ? $this->configuration['upscale'] : 0,
'#default_value' => $this->configuration['upscale'],
'#title' => t('Allow Upscaling'),
'#description' => t('Let scale make images larger than their original size'),
);
......
......@@ -70,7 +70,7 @@ public function execute($entity = NULL) {
/**
* {@inheritdoc}
*/
protected function getDefaultConfiguration() {
public function defaultConfiguration() {
return array(
'owner_uid' => '',
);
......
......@@ -39,7 +39,7 @@ public function execute($node = NULL) {
/**
* {@inheritdoc}
*/
protected function getDefaultConfiguration() {
public function defaultConfiguration() {
return array(
'keywords' => array(),
);
......
......@@ -22,9 +22,9 @@
class RecentContentBlock extends BlockBase {
/**
* Overrides \Drupal\block\BlockBase::settings().
* {@inheritdoc}
*/
public function settings() {
public function defaultConfiguration() {
return array(
'block_count' => 10,
);
......
......@@ -22,9 +22,9 @@
class SyndicateBlock extends BlockBase {
/**
* Overrides \Drupal\block\BlockBase::settings().
* {@inheritdoc}
*/
public function settings() {
public function defaultConfiguration() {
return array(
'block_count' => 10,
);
......
......@@ -43,9 +43,9 @@ class StatisticsPopularBlock extends BlockBase {
protected $last_list;
/**
* Overrides \Drupal\block\BlockBase::settings().
* {@inheritdoc}
*/
public function settings() {
public function defaultConfiguration() {
return array(
'top_day_num' => 0,
'top_all_num' => 0,
......
......@@ -17,7 +17,7 @@ abstract class ChangeUserRoleBase extends ConfigurableActionBase {
/**
* {@inheritdoc}
*/
protected function getDefaultConfiguration() {
public function defaultConfiguration() {
return array(
'rid' => '',
);
......
......@@ -22,9 +22,9 @@
class UserNewBlock extends BlockBase {
/**
* Overrides \Drupal\block\BlockBase::settings().
* {@inheritdoc}
*/
public function settings() {
public function defaultConfiguration() {
return array(
'properties' => array(
'administrative' => TRUE
......
......@@ -25,9 +25,9 @@
class UserOnlineBlock extends BlockBase {
/**
* Overrides \Drupal\block\BlockBase::settings().
* {@inheritdoc}
*/
public function settings() {
public function defaultConfiguration() {
return array(
'properties' => array(
'administrative' => TRUE
......
......@@ -45,7 +45,7 @@ public function build() {
/**
* {@inheritdoc}
*/
public function settings() {
public function defaultConfiguration() {
$settings = array();
if ($this->displaySet) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment