class-field-choice.php 879 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin\ConfigurationUI
  6. */
  7. /**
  8. * Class WPSEO_Config_Field_Choice.
  9. */
  10. class WPSEO_Config_Field_Choice extends WPSEO_Config_Field {
  11. /**
  12. * WPSEO_Config_Field_Choice constructor.
  13. *
  14. * @param string $field Field name to use.
  15. */
  16. public function __construct( $field ) {
  17. parent::__construct( $field, 'Choice' );
  18. $this->properties['choices'] = [];
  19. }
  20. /**
  21. * Add a choice to the properties.
  22. *
  23. * @param string $value Value op the option.
  24. * @param string $label Label to display for the value.
  25. * @param string $aria_label Optional. Aria label text to use.
  26. */
  27. public function add_choice( $value, $label, $aria_label = '' ) {
  28. $choice = [
  29. 'label' => $label,
  30. ];
  31. if ( $aria_label ) {
  32. $choice['screenReaderText'] = $aria_label;
  33. }
  34. $this->properties['choices'][ $value ] = $choice;
  35. }
  36. }