injector = $injector; } /** * Returns data array for use in inline script. * * @since 1.5.0 * * @return array>> Script data. */ public function get_script_data(): array { $views = $this->get_layouts(); $view_types = []; foreach ( $views as $view_key => $view_label ) { $view_types[] = [ 'label' => $view_label, 'value' => $view_key, ]; } $field_states = $this->fields_states(); return [ 'views' => $view_types, 'fields' => $field_states, ]; } /** * Wrapper function for fetching field states * based on the view types. * * Mainly uses FieldState and Fields classes. * * @since 1.5.0 * * @return array>>> Field states. */ public function fields_states(): array { $field_states = []; /** * Factory instance. * * @var Factory */ $factory = $this->injector->make( Factory::class ); $views = $this->get_layouts(); $fields = [ 'title', 'author', 'date', 'image_alignment', 'excerpt', 'sharp_corners', 'archive_link', 'circle_size', 'number_of_columns', ]; foreach ( array_keys( $views ) as $view_type ) { $field_state = $factory->get_field( (string) $view_type ); foreach ( $fields as $field ) { $field_states[ $view_type ][ $field ] = [ 'show' => $field_state->$field()->show(), 'label' => $field_state->$field()->label(), 'hidden' => $field_state->$field()->hidden(), ]; } } return $field_states; } /** * Get supported layouts for web stories. * * @since 1.14.0 * * @return array */ public function get_layouts(): array { return [ 'carousel' => __( 'Box Carousel', 'web-stories' ), 'circles' => __( 'Circle Carousel', 'web-stories' ), 'grid' => __( 'Grid', 'web-stories' ), 'list' => __( 'List', 'web-stories' ), ]; } }