<?php
|
namespace JVBase\managers\SEO\render\Traits\_Properties;
|
|
use JVBase\managers\SEO\render\Thing\Intangible\StructuredValue\PropertyValue;
|
use JVBase\managers\SEO\render\Traits\_Helpers\arrayHelper;
|
|
if (!defined('ABSPATH')) {
|
exit;
|
}
|
trait additionalPropertyTrait {
|
use arrayHelper;
|
/**
|
* @var PropertyValue|array A property-value pair representing an additional characteristic of the entity, e.g. a product feature or another characteristic for which there is no matching property in schema.org.
|
*
|
* Note: Publishers should be aware that applications designed to use specific schema.org properties (e.g. https://schema.org/width, https://schema.org/color, https://schema.org/gtin13, ...) will typically expect such data to be provided using those properties, rather than using the generic property/value mechanism.
|
*/
|
protected PropertyValue|array $additionalProperty;
|
|
public function getAdditionalProperty():PropertyValue|array|null
|
{
|
return $this->additionalProperty??null;
|
}
|
public function setAdditionalProperty(PropertyValue|array $additionalProperty):void
|
{
|
if (is_array($additionalProperty)) {
|
if (!is_numeric(array_key_first($additionalProperty))) {
|
$additionalProperty = [$additionalProperty];
|
}
|
$additionalProperty = array_map(function($property) {
|
if (!array_key_exists('type', $property)) {
|
$property['type'] = 'JVBase\managers\SEO\render\Thing\Intangible\StructuredValue\PropertyValue';
|
}
|
return $property;
|
}, $additionalProperty);
|
$additionalProperty = $this->classArray('additionalProperty', $additionalProperty, 'JVBase\managers\SEO\render\Thing\Intangible\StructuredValue\PropertyValue');
|
|
$additionalProperty = array_filter($additionalProperty, function ($property) {
|
return property_exists($property, 'value') && !empty($property->value);
|
});
|
}
|
if (!empty($this->additionalProperty)) {
|
if (!is_array($this->additionalProperty)) {
|
$this->additionalProperty = [$this->additionalProperty];
|
}
|
$additionalProperty = array_merge($this->additionalProperty, $additionalProperty);
|
}
|
$this->additionalProperty = $additionalProperty;
|
}
|
|
public function getAdditionalPropertyFieldConfig():array
|
{
|
return [
|
'type' => 'repeater',
|
'label' => 'Additional Properties',
|
'hint' => 'If you need to define another property that does not exist anywhere on this page, add it here.',
|
'fields' => [
|
'name' => [
|
'type' => 'text',
|
'label' => 'Name'
|
],
|
'propertyID' => [
|
'type' => 'text',
|
'label' => 'Property ID',
|
'hint' => 'A commonly used identifier for the characteristic represented by the property, e.g. a manufacturer or a standard code for a property. propertyID can be (1) a prefixed string, mainly meant to be used with standards for product properties; (2) a site-specific, non-prefixed string (e.g. the primary key of the property or the vendor-specific ID of the property), or (3) a URL indicating the type of the property, either pointing to an external vocabulary, or a Web resource that describes the property (e.g. a glossary entry). Standards bodies should promote a standard prefix for the identifiers of properties from their standards.'
|
],
|
'value' => [
|
'type' => 'textarea',
|
'label' => 'Value'
|
]
|
]
|
];
|
}
|
}
|