Back to Microdata class

Method fallback

public \Joomla\CMS\Microdata\Microdata
fallback
(mixed $type, mixed $property)
Setup a Fallback Type and Property
Parameters
  • string $type The Fallback Type
  • string $property The Fallback Property
Returns
  • \Joomla\CMS\Microdata\Microdata Instance of $this
Since
  • 3.2
Class: Microdata
Project: Joomla

Method fallback - Source code

/**
 * Setup a Fallback Type and Property
 *
 * @param   string  $type      The Fallback Type
 * @param   string  $property  The Fallback Property
 *
 * @return  Microdata  Instance of $this
 *
 * @since   3.2
 */
public function fallback($type, $property)
{
    if (!$this->enabled) {
        return $this;
    }
    // Sanitize the $Type
    $this->fallbackType = static::sanitizeType($type);
    // If the given $Type isn't available, fallback to 'Thing' Type
    if (!static::isTypeAvailable($this->fallbackType)) {
        $this->fallbackType = 'Thing';
    }
    // Control if the $Property exist in the given $Type and setup it, otherwise leave it 'NULL'
    if (static::isPropertyInType($this->fallbackType, $property)) {
        $this->fallbackProperty = $property;
    } else {
        $this->fallbackProperty = null;
    }
    return $this;
}