visible; } /** * Determines whether the field accepts input. * * @return bool True when enabled. */ public function is_enabled(): bool { return $this->enabled; } /** * Determines whether the field must be filled in. * * @return bool True when required. */ public function is_required(): bool { return $this->required; } /** * Determines whether the field takes part in the submission at all. * * A field the visitor could neither see nor use has nothing to say, so its * value is discarded rather than validated. * * @return bool True when the field should be validated and stored. */ public function is_active(): bool { return $this->visible && $this->enabled; } /** * Returns a copy with a different visibility. * * @param bool $visible Whether the field is shown. */ public function with_visible( bool $visible ): FieldState { return new self( $visible, $this->enabled, $this->required ); } /** * Returns a copy with a different enabled flag. * * @param bool $enabled Whether the field accepts input. */ public function with_enabled( bool $enabled ): FieldState { return new self( $this->visible, $enabled, $this->required ); } /** * Returns a copy with a different required flag. * * @param bool $required Whether the field must be filled in. */ public function with_required( bool $required ): FieldState { return new self( $this->visible, $this->enabled, $required ); } }