class-configuration-components.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin\ConfigurationUI
  6. */
  7. /**
  8. * Class WPSEO_Configuration_Components.
  9. */
  10. class WPSEO_Configuration_Components {
  11. /**
  12. * List of registered components.
  13. *
  14. * @var WPSEO_Config_Component[]
  15. */
  16. protected $components = [];
  17. /**
  18. * Adapter.
  19. *
  20. * @var WPSEO_Configuration_Options_Adapter
  21. */
  22. protected $adapter;
  23. /**
  24. * Add default components.
  25. */
  26. public function initialize() {
  27. $this->add_component( new WPSEO_Config_Component_Mailchimp_Signup() );
  28. $this->add_component( new WPSEO_Config_Component_Suggestions() );
  29. }
  30. /**
  31. * Add a component.
  32. *
  33. * @param WPSEO_Config_Component $component Component to add.
  34. */
  35. public function add_component( WPSEO_Config_Component $component ) {
  36. $this->components[] = $component;
  37. }
  38. /**
  39. * Sets the storage to use.
  40. *
  41. * @param WPSEO_Configuration_Storage $storage Storage to use.
  42. */
  43. public function set_storage( WPSEO_Configuration_Storage $storage ) {
  44. $this->set_adapter( $storage->get_adapter() );
  45. foreach ( $this->components as $component ) {
  46. $storage->add_field( $component->get_field() );
  47. }
  48. }
  49. /**
  50. * Sets the adapter to use.
  51. *
  52. * @param WPSEO_Configuration_Options_Adapter $adapter Adapter to use.
  53. */
  54. public function set_adapter( WPSEO_Configuration_Options_Adapter $adapter ) {
  55. $this->adapter = $adapter;
  56. foreach ( $this->components as $component ) {
  57. $adapter->add_custom_lookup(
  58. $component->get_field()->get_identifier(),
  59. [
  60. $component,
  61. 'get_data',
  62. ],
  63. [
  64. $component,
  65. 'set_data',
  66. ]
  67. );
  68. }
  69. }
  70. }