Element.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace Drupal\Core\Config\Schema;
  3. use Drupal\Core\Config\TypedConfigManagerInterface;
  4. use Drupal\Core\TypedData\TypedData;
  5. use Drupal\Core\TypedData\TypedDataManagerInterface;
  6. /**
  7. * Defines a generic configuration element.
  8. */
  9. abstract class Element extends TypedData {
  10. /**
  11. * The configuration value.
  12. *
  13. * @var mixed
  14. */
  15. protected $value;
  16. /**
  17. * Gets the typed configuration manager.
  18. *
  19. * Overrides \Drupal\Core\TypedData\TypedDataTrait::getTypedDataManager() to
  20. * ensure the typed configuration manager is returned.
  21. *
  22. * @return \Drupal\Core\Config\TypedConfigManagerInterface
  23. * The typed configuration manager.
  24. */
  25. public function getTypedDataManager() {
  26. if (empty($this->typedDataManager)) {
  27. $this->setTypedDataManager(\Drupal::service('config.typed'));
  28. }
  29. return $this->typedDataManager;
  30. }
  31. /**
  32. * Sets the typed config manager.
  33. *
  34. * Overrides \Drupal\Core\TypedData\TypedDataTrait::setTypedDataManager() to
  35. * ensure that only typed configuration manager can be used.
  36. *
  37. * @param \Drupal\Core\TypedData\TypedDataManagerInterface $typed_data_manager
  38. * The typed config manager. This must be an instance of
  39. * \Drupal\Core\Config\TypedConfigManagerInterface. If it is not, then this
  40. * method will error when assertions are enabled. We can not narrow the
  41. * typehint as this will cause PHP errors.
  42. *
  43. * @return $this
  44. */
  45. public function setTypedDataManager(TypedDataManagerInterface $typed_data_manager) {
  46. assert($typed_data_manager instanceof TypedConfigManagerInterface, '$typed_data_manager should be an instance of \Drupal\Core\Config\TypedConfigManagerInterface.');
  47. $this->typedDataManager = $typed_data_manager;
  48. return $this;
  49. }
  50. }