diff --git a/includes/Blocks/CorePostTerms.php b/includes/Blocks/CorePostTerms.php index 740857e3..c270f68d 100644 --- a/includes/Blocks/CorePostTerms.php +++ b/includes/Blocks/CorePostTerms.php @@ -15,15 +15,51 @@ * Class CorePostTerms. */ class CorePostTerms extends Block { + /** + * String fields for the block. + */ + public const STRING_FIELDS = [ 'prefix', 'suffix', 'term' ]; + /** * {@inheritDoc} */ public function __construct( WP_Block_Type $block, Registry $block_registry ) { parent::__construct( $block, $block_registry ); + foreach ( self::STRING_FIELDS as $field ) { + $this->register_string_field( $field ); + } + $this->register_list_of_terms_field(); } + /** + * Registers a string field for the block. + * + * @param string $name The name of the field. + * + * @return void + * @throws \Exception + */ + protected function register_string_field( $name ) { + register_graphql_field( + $this->type_name, + $name, + [ + 'type' => 'String', + 'description' => sprintf( + // translators: %1$s is the field name, %2$s is the block type name. + __( '%1$s of the "%2$s" Block Type', 'wp-graphql-content-blocks' ), + ucfirst( $name ), + $this->type_name + ), + 'resolve' => static function ( $block ) use ( $name ) { + return isset($block['attrs'][$name]) ? (string) $block['attrs'][$name] : null; + }, + ] + ); + } + /** * Registers a list of terms field for the block. *