Element::to_json( bool $include_meta = true, awsmug\Torro_Forms\DB_Objects\Submissions\Submission|null $submission = null )

Returns an array representation of the model.

Description

See also

Parameters

$include_meta

(bool) (Optional) Whether to include metadata for each model in the collection.

Default value: true

$submission

(awsmug\Torro_Forms\DB_Objects\Submissions\Submission|null) (Optional) Submission to get the values from, if available.

Default value: null

Return

(array) Array including all information for the model.

Source

File: src/db-objects/elements/element.php

	public function to_json( $include_meta = true, $submission = null ) {
		$data = parent::to_json( $include_meta );

		/**
		 * Filters the element input classes.
		 *
		 * @since 1.0.0
		 *
		 * @param array $input_classes Array of input classes.
		 */
		$input_classes = apply_filters( "{$this->manager->get_prefix()}element_input_classes", array( 'torro-element-input' ) );

		/**
		 * Filters the element label classes.
		 *
		 * @since 1.0.0
		 *
		 * @param array $label_classes Array of label classes.
		 */
		$label_classes = apply_filters( "{$this->manager->get_prefix()}element_label_classes", array( 'torro-element-label' ) );

		/**
		 * Filters the element wrap classes.
		 *
		 * @since 1.0.0
		 *
		 * @param array $wrap_classes Array of wrap classes.
		 */
		$wrap_classes = apply_filters( "{$this->manager->get_prefix()}element_wrap_classes", array( 'torro-element-wrap' ) );

		/**
		 * Filters the element description classes.
		 *
		 * @since 1.0.0
		 *
		 * @param array $description_classes Array of description classes.
		 */
		$description_classes = apply_filters( "{$this->manager->get_prefix()}element_description_classes", array( 'torro-element-description' ) );

		/**
		 * Filters the element errors classes, for the error messages wrap.
		 *
		 * @since 1.0.0
		 *
		 * @param array $errors_classes Array of errors classes.
		 */
		$errors_classes = apply_filters( "{$this->manager->get_prefix()}element_errors_classes", array( 'torro-element-errors' ) );

		$data = array_merge( $data, array(
			'value'             => null,
			'input_attrs'       => array(
				'id'       => 'torro-element-' . $this->id,
				'name'     => 'torro_submission[values][' . $this->id . '][_main]',
				'class'    => implode( ' ', $input_classes ),
			),
			'label_required'    => '',
			'label_attrs'       => array(
				'id'    => 'torro-element-' . $this->id . '-label',
				'class' => implode( ' ', $label_classes ),
				'for'   => 'torro-element-' . $this->id,
			),
			'wrap_attrs'        => array(
				'id'    => 'torro-element-' . $this->id . '-wrap',
				'class' => implode( ' ', $wrap_classes ),
			),
			'description'       => '',
			'description_attrs' => array(
				'id'    => 'torro-element-' . $this->id . '-description',
				'class' => implode( ' ', $description_classes ),
			),
			'errors'            => array(),
			'errors_attrs'      => array(
				'id'    => 'torro-element-' . $this->id . '-errors',
				'class' => implode( ' ', $errors_classes ),
			),
			'before'            => '',
			'after'             => '',
		) );

		if ( has_action( "{$this->manager->get_prefix()}element_before" ) ) {
			ob_start();

			/**
			 * Allows to print additional content before an element in the frontend.
			 *
			 * @since 1.0.0
			 *
			 * @param int $element_id Element ID.
			 */
			do_action( "{$this->manager->get_prefix()}element_before", $this->id );

			$data['before'] = ob_get_clean();
		}

		if ( has_action( "{$this->manager->get_prefix()}element_after" ) ) {
			ob_start();

			/**
			 * Allows to print additional content after an element in the frontend.
			 *
			 * @since 1.0.0
			 *
			 * @param int $element_id Element ID.
			 */
			do_action( "{$this->manager->get_prefix()}element_after", $this->id );

			$data['after'] = ob_get_clean();
		}

		$element_type = $this->get_element_type();
		if ( $element_type ) {
			$data = $element_type->filter_json( $data, $this, $submission );
		}

		/**
		 * Filters the main element value.
		 *
		 * @since 1.0.0
		 *
		 * @param mixed   $value   Element value.
		 * @param Element $element Element object.
		 */
		$data['value'] = apply_filters( "{$this->manager->get_prefix()}element_value", $data['value'], $this );

		return $data;
	}

Changelog

Changelog
Version Description
1.0.0 Introduced.