REST_Elements_Controller::prepare_links( awsmug\Torro_Forms\DB_Objects\Elements\Element $element )

Prepares links for the request.

Description

Parameters

$element

(awsmug\Torro_Forms\DB_Objects\Elements\Element) (Required) Element object.

Return

(array) Links for the given element.

Source

File: src/db-objects/elements/rest-elements-controller.php

	protected function prepare_links( $element ) {
		$links = parent::prepare_links( $element );

		if ( ! empty( $element->type ) ) {
			$links['about'] = array(
				'href' => rest_url( trailingslashit( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ) . 'types/' . $element->type ),
			);
		}

		if ( ! empty( $element->container_id ) ) {
			$links['parent_container'] = array(
				'href' => rest_url( trailingslashit( sprintf( '%s/%s', $this->namespace, 'containers' ) ) . $element->container_id ),
			);
		}

		$primary_property = $this->manager->get_primary_property();

		$links['element_choices'] = array(
			'href'       => add_query_arg( array(
				'element_id' => $element->$primary_property,
				'per_page'   => 250,
			), rest_url( sprintf( '%s/%s', $this->namespace, 'element_choices' ) ) ),
			'embeddable' => true,
		);

		$links['element_settings'] = array(
			'href'       => add_query_arg( array(
				'element_id' => $element->$primary_property,
				'per_page'   => 250,
			), rest_url( sprintf( '%s/%s', $this->namespace, 'element_settings' ) ) ),
			'embeddable' => true,
		);

		return $links;
	}

Changelog

Changelog
Version Description
1.0.0 Introduced.