MatcherBase.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * @file
  4. * Contains \Drupal\linkit\MatcherBase.
  5. */
  6. namespace Drupal\linkit;
  7. use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
  8. use Drupal\Core\Plugin\PluginBase;
  9. /**
  10. * Provides a base class for matchers.
  11. *
  12. * @see plugin_api
  13. */
  14. abstract class MatcherBase extends PluginBase implements MatcherInterface, ContainerFactoryPluginInterface {
  15. /**
  16. * The matcher ID.
  17. *
  18. * @var string
  19. */
  20. protected $uuid;
  21. /**
  22. * The weight of the matcher compared to others in a matcher collection.
  23. *
  24. * @var int
  25. */
  26. protected $weight = 0;
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public function __construct(array $configuration, $plugin_id, $plugin_definition) {
  31. parent::__construct($configuration, $plugin_id, $plugin_definition);
  32. $this->setConfiguration($configuration);
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function getUuid() {
  38. return $this->uuid;
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function getLabel() {
  44. return $this->pluginDefinition['label'];
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function getSummary() {
  50. return array();
  51. }
  52. /**
  53. * {@inheritdoc}
  54. */
  55. public function getWeight() {
  56. return $this->weight;
  57. }
  58. /**
  59. * {@inheritdoc}
  60. */
  61. public function setWeight($weight) {
  62. return $this->weight = $weight;
  63. }
  64. /**
  65. * {@inheritdoc}
  66. */
  67. public function getConfiguration() {
  68. return [
  69. 'uuid' => $this->getUuid(),
  70. 'id' => $this->getPluginId(),
  71. 'weight' => $this->getWeight(),
  72. 'settings' => $this->configuration,
  73. ];
  74. }
  75. /**
  76. * {@inheritdoc}
  77. */
  78. public function setConfiguration(array $configuration) {
  79. $configuration += [
  80. 'uuid' => '',
  81. 'weight' => '0',
  82. 'settings' => [],
  83. ];
  84. $this->configuration = $configuration['settings'] + $this->defaultConfiguration();
  85. $this->uuid = $configuration['uuid'];
  86. $this->weight = $configuration['weight'];
  87. return $this;
  88. }
  89. /**
  90. * {@inheritdoc}
  91. */
  92. public function defaultConfiguration() {
  93. return [];
  94. }
  95. /**
  96. * {@inheritdoc}
  97. */
  98. public function calculateDependencies() {
  99. return [];
  100. }
  101. }