tainacan/docs/class-reference-fields.md

516 lines
10 KiB
Markdown
Raw Normal View History

# Metadata
2018-04-02 02:08:46 +00:00
## Metadatum Repository
2018-04-02 02:08:46 +00:00
<!-- BEGIN DOC-COMMENT H3 src/classes/repositories/class-tainacan-metadata.php -->
### `class Metadata extends Repository`
2018-04-02 02:08:46 +00:00
Class Metadata
2018-04-02 02:08:46 +00:00
### `protected function __construct()`
Register specific hooks for metadatum repository
2018-04-02 02:08:46 +00:00
### `public function get_cpt_labels()`
Get the labels for the custom post type of this repository
**Returns:** `array` — Labels in the format expected by register_post_type()
### `public function get_default_metadata_attribute()`
constant used in default metadatum in attribute collection_id
2018-04-02 02:08:46 +00:00
**Returns:** `string` — the value of constant
### `public function register_field_type( $class_name )`
register metadatum types class on array of types
2018-04-02 02:08:46 +00:00
**Parameters:**
* `string` — $class_name — | object The class name or the instance
### `public function unregister_field_type( $class_name )`
register metadatum types class on array of types
2018-04-02 02:08:46 +00:00
**Parameters:**
* `string` — $class_name — | object The class name or the instance
### `public function fetch( $args, $output = null )`
fetch metadatum based on ID or WP_Query args
2018-04-02 02:08:46 +00:00
metadatum are stored as posts. Check WP_Query docs to learn all args accepted in the $args parameter (@see https://developer.wordpress.org/reference/classes/wp_query/) You can also use a mapped property, such as name and description, as an argument and it will be mapped to the appropriate WP_Query argument
2018-04-02 02:08:46 +00:00
**Parameters:**
* `$args` — array — WP_Query args || int $args the metadatum id
2018-04-02 02:08:46 +00:00
* `$output` — string — The desired output format (@see \Tainacan\Repositories\Repository::fetch_output() for possible values)
**Returns:** `Entities\Metadatum|\WP_Query|Array` — an instance of wp query OR array of entities;
2018-04-02 02:08:46 +00:00
### `public function fetch_by_collection(Entities\Collection $collection, $args = [], $output = null)`
fetch metadatum by collection, searches all metadatum available
2018-04-02 02:08:46 +00:00
**Parameters:**
* `$collection` — Entities\Collection
* `$args` — array — WP_Query args plus disabled_fields
* `$output` — string — The desired output format (@see \Tainacan\Repositories\Repository::fetch_output() for possible values)
**Returns:** `array` — Entities\Metadatum
2018-04-02 02:08:46 +00:00
### `public function order_result( $result, Entities\Collection $collection, $include_disabled = false )`
Ordinate the result from fetch response if $collection has an ordination, metadata not ordinated appear on the end of the list
2018-04-02 02:08:46 +00:00
**Parameters:**
* `Response` — $result — from method fetch
* `$collection` — Entities\Collection
* `$include_disabled` — bool — Wether to include disabled metadata in the results or not
2018-04-02 02:08:46 +00:00
**Returns:** `array` — or WP_Query ordinate
### `public function insert($metadatum)`
2018-04-02 02:08:46 +00:00
{@inheritDoc}
**Parameters:**
* `$metadatum` — \Tainacan\Entities\Metadatum
2018-04-02 02:08:46 +00:00
**Returns:** \Tainacan\Entities\Metadatum
2018-04-02 02:08:46 +00:00
### `public function update($object, $new_values = null)`
**Returns:** mixed|string|Entities\Entity
### `public function fetch_field_types( $output = 'CLASS')`
fetch all registered metadatum type classes
2018-04-02 02:08:46 +00:00
Possible outputs are: CLASS (default) - returns the Class name of of metadatum types registered NAME - return an Array of the names of metadatum types registered
2018-04-02 02:08:46 +00:00
**Parameters:**
* `string` — $output — CLASS | NAME
**Returns:** `array` — of Entities\Metadatum_Types\Metadatum_Type classes path name
2018-04-02 02:08:46 +00:00
### `public function register_core_fields( Entities\Collection $collection )`
**Parameters:**
* `$collection` — Entities\Collection
**Returns:** bool
### `public function disable_delete_core_fields( $before, $post )`
block user from remove core metadata
2018-04-02 02:08:46 +00:00
**Parameters:**
* `wordpress` — $before — pass a null value
* `the` — $post — post which is moving to trash
**Returns:** null/bool
### `public function force_delete_core_fields( $before, $post, $force_delete )`
block user from remove core metadata ( if use wp_delete_post)
2018-04-02 02:08:46 +00:00
**Parameters:**
* `wordpress` — $before — pass a null value
* `the` — $post — post which is deleting
* `a` — $force_delete — boolean that force the deleting
**Returns:** `null` — /bool
### `public function get_core_fields( Entities\Collection $collection )`
returns all core items from a specific collection
**Parameters:**
* `$collection` — Entities\Collection
**Returns:** Array|\WP_Query
### `public function insert_array_field( $data )`
create a metadatum entity and insert by an associative array ( attribute => value )
2018-04-02 02:08:46 +00:00
**Parameters:**
* `$data` — Array — the array of attributes to insert a metadatum
2018-04-02 02:08:46 +00:00
**Returns:** `int` — the metadatum id inserted
2018-04-02 02:08:46 +00:00
### `public function fetch_all_field_values($collection_id, $metadatum_id)`
2018-04-02 02:08:46 +00:00
Fetch all values of a metadatum from a collection in all it collection items
2018-04-02 02:08:46 +00:00
**Returns:** array|null|object
### `private function pre_update_taxonomy_field($metadatum)`
2018-04-02 02:08:46 +00:00
Stores the value of the taxonomy_id option to use on update_taxonomy_field method.
2018-04-02 02:08:46 +00:00
### `private function update_taxonomy_field($metadatum)`
2018-04-02 02:08:46 +00:00
Triggers hooks when saving a Taxonomy Metadatum, indicating wich taxonomy was added or removed from a collection.
2018-04-02 02:08:46 +00:00
This is used by Taxonomies repository to update the collections_ids property of the taxonomy as a metadatum type taxonomy is inserted or removed
2018-04-02 02:08:46 +00:00
**Parameters:**
* `$metadatum` — [type] — [description]
2018-04-02 02:08:46 +00:00
**Returns:** `[type]` — [description]
<!-- END DOC-COMMENT -->
## Metadatum Entity
2018-04-02 02:08:46 +00:00
<!-- BEGIN DOC-COMMENT H3 src/classes/entities/class-tainacan-metadatum.php -->
### `class Metadatum extends Entity`
2018-04-02 02:08:46 +00:00
Represents the Entity Metadatum
2018-04-02 02:08:46 +00:00
### `protected $repository = 'Metadata'`
2018-04-02 02:08:46 +00:00
{@inheritDoc}
### `function get_name()`
Return the metadatum name
2018-04-02 02:08:46 +00:00
**Returns:** string
### `function get_slug()`
Get metadatum slug
2018-04-02 02:08:46 +00:00
**Returns:** string
### `function get_order()`
Return the metadatum order type
2018-04-02 02:08:46 +00:00
**Returns:** string
### `function get_parent()`
Return the parent ID
**Returns:** string
### `function get_description()`
Return the metadatum description
2018-04-02 02:08:46 +00:00
**Returns:** string
### `function get_required()`
Return if is a required metadatum
2018-04-02 02:08:46 +00:00
**Returns:** boolean
### `function get_multiple()`
Return if is a multiple metadatum
2018-04-02 02:08:46 +00:00
**Returns:** boolean
### `function get_cardinality()`
Return the cardinality
**Returns:** string
### `function get_collection_key()`
Return if metadatum is key
2018-04-02 02:08:46 +00:00
**Returns:** boolean
### `function get_mask()`
Return the mask
**Returns:** string
### `function get_default_value()`
Return the metadatum default value
2018-04-02 02:08:46 +00:00
**Returns:** `string` — || integer
### `function get_field_type_object()`
Return the an object child of \Tainacan\Metadatum_Types\Metadatum_Type with options
2018-04-02 02:08:46 +00:00
**Returns:** `\Tainacan\Metadatum_Types\Metadatum_Type` — The metadatum type class with filled options
2018-04-02 02:08:46 +00:00
### `function get_field_type()`
Return the class name for the metadatum type
2018-04-02 02:08:46 +00:00
**Returns:** `string` — The
### `function get_field_type_options()`
Return the actual options for the current metadatum type
2018-04-02 02:08:46 +00:00
**Returns:** `array` — Configurations for the metadatum type object
2018-04-02 02:08:46 +00:00
### `function set_name($value)`
Set the metadatum name
2018-04-02 02:08:46 +00:00
**Parameters:**
* `$value` — [string]
**Returns:** void
### `function get_accept_suggestion()`
Return true if this metadatum allow community suggestions, false otherwise
2018-04-02 02:08:46 +00:00
**Returns:** bool
### `function set_slug($value)`
Set the metadatum slug
2018-04-02 02:08:46 +00:00
If you dont set the metadatum slug, it will be set automatically based on the name and following WordPress default behavior of creating slugs for posts.
2018-04-02 02:08:46 +00:00
If you set the slug for an existing one, WordPress will append a number at the end of in order to make it unique (e.g slug-1, slug-2)
**Parameters:**
* `$value` — [string]
**Returns:** void
### `function set_order($value)`
Set manually the order of the metadatum
2018-04-02 02:08:46 +00:00
**Parameters:**
* `$value` — [string]
**Returns:** void
### `function set_parent($value)`
Set the metadatum parent ID
2018-04-02 02:08:46 +00:00
**Parameters:**
* `$value` — [integer] — The ID from parent
**Returns:** void
### `function set_description($value)`
Set metadatum description
2018-04-02 02:08:46 +00:00
**Parameters:**
* `$value` — [string] — The text description
**Returns:** void
### `function set_required( $value )`
Allow the metadatum be required
2018-04-02 02:08:46 +00:00
**Parameters:**
* `$value` — [boolean]
**Returns:** void
### `function set_multiple( $value )`
Allow multiple metadata
2018-04-02 02:08:46 +00:00
**Parameters:**
* `$value` — [boolean]
**Returns:** void
### `function set_cardinality( $value )`
The number of possible metadata
2018-04-02 02:08:46 +00:00
**Parameters:**
* `$value` — [string]
**Returns:** void
### `function set_collection_key( $value )`
Define if the value is key on the collection
**Parameters:**
* `$value` — [string]
**Returns:** void
### `function set_mask( $value )`
Set mask for the metadatum
2018-04-02 02:08:46 +00:00
**Parameters:**
* `$value` — [string]
**Returns:** void
### `function set_privacy( $value )`
Set privacy
**Parameters:**
* `$value` — [string]
**Returns:** void
### `function set_default_value( $value )`
Set default value
**Parameters:**
* `||` — [string — integer] $value
**Returns:** void
### `public function set_field_type( $value )`
set the metadatum type class name
2018-04-02 02:08:46 +00:00
**Parameters:**
* `|` — string — \Tainacan\Metadatum_Types\Metadatum_Type $value The name of the class or the instance
2018-04-02 02:08:46 +00:00
### `function set_accept_suggestion( $value )`
Set if this metadatum allow community suggestions
2018-04-02 02:08:46 +00:00
**Parameters:**
* `$value` — bool
### `function set_field_type_options( $value )`
Set Metadatum type options
2018-04-02 02:08:46 +00:00
**Parameters:**
* `||` — [string — integer] $value
**Returns:** void
### `public function get_enabled_for_collection()`
Transient property used to store the status of the metadatum for a particular collection
2018-04-02 02:08:46 +00:00
Used by the API to tell front end when a metadatum is disabled
2018-04-02 02:08:46 +00:00
### `function is_multiple()`
Return true if is multiple, else return false
**Returns:** boolean
### `function is_collection_key()`
Return true if is collection key, else return false
**Returns:** boolean
### `function is_required()`
Return true if is required, else return false
**Returns:** boolean
### `public function validate()`
{@inheritdoc }
Also validates the metadatum, calling the validate_options callback of the Metadatum Type
2018-04-02 02:08:46 +00:00
**Returns:** `bool` — valid or not
<!-- END DOC-COMMENT -->