/**
* This function handles the display logic.
* It checks if the Type, Property are available, if not check for a Fallback,
* then reset all params for the next use and return the HTML.
*
* @param string $displayType Optional, 'inline', available options ['inline'|'span'|'div'|meta]
* @param boolean $emptyOutput Return an empty string if the library output is disabled and there is a $content value
*
* @return string
*
* @since 3.2
*/
public function display($displayType = '', $emptyOutput = false)
{
// Initialize the HTML to output
$html = $this->content !== null && !$emptyOutput ? $this->content : '';
// Control if the library output is enabled, otherwise return the $content or an empty string
if (!$this->enabled) {
// Reset params
$this->resetParams();
return $html;
}
// If the $property is wrong for the current $Type check if a Fallback is available, otherwise return an empty HTML
if ($this->property) {
// Process and return the HTML the way the user expects to
if ($displayType) {
switch ($displayType) {
case 'span':
$html = static::htmlSpan($html, $this->property);
break;
case 'div':
$html = static::htmlDiv($html, $this->property);
break;
case 'meta':
$html = $this->machineContent ?? $html;
$html = static::htmlMeta($html, $this->property);
break;
default:
// Default $displayType = 'inline'
$html = static::htmlProperty($this->property);
break;
}
} else {
/*
* Process and return the HTML in an automatic way,
* with the $Property expected Types and display everything in the right way,
* check if the $Property is 'normal', 'nested' or must be rendered in a metadata tag
*/
switch (static::getExpectedDisplayType($this->type, $this->property)) {
case 'nested':
// Retrieve the expected 'nested' Type of the $Property
$nestedType = static::getExpectedTypes($this->type, $this->property);
$nestedProperty = '';
// If there is a Fallback Type then probably it could be the expectedType
if (\in_array($this->fallbackType, $nestedType)) {
$nestedType = $this->fallbackType;
if ($this->fallbackProperty) {
$nestedProperty = $this->fallbackProperty;
}
} else {
$nestedType = $nestedType[0];
}
// Check if a $content is available, otherwise fallback to an 'inline' display type
if ($this->content !== null) {
if ($nestedProperty) {
$html = static::htmlSpan($this->content, $nestedProperty);
}
$html = static::htmlSpan($html, $this->property, $nestedType, true);
} else {
$html = static::htmlProperty($this->property) . ' ' . static::htmlScope($nestedType);
if ($nestedProperty) {
$html .= ' ' . static::htmlProperty($nestedProperty);
}
}
break;
case 'meta':
// Check if a $content is available, otherwise fallback to an 'inline' display type
if ($this->content !== null) {
$html = $this->machineContent ?? $this->content;
$html = static::htmlMeta($html, $this->property) . $this->content;
} else {
$html = static::htmlProperty($this->property);
}
break;
default:
/*
* Default expected display type = 'normal'
* Check if a $content is available,
* otherwise fallback to an 'inline' display type
*/
if ($this->content !== null) {
$html = static::htmlSpan($this->content, $this->property);
} else {
$html = static::htmlProperty($this->property);
}
break;
}
}
} elseif ($this->fallbackProperty) {
// Process and return the HTML the way the user expects to
if ($displayType) {
switch ($displayType) {
case 'span':
$html = static::htmlSpan($html, $this->fallbackProperty, $this->fallbackType);
break;
case 'div':
$html = static::htmlDiv($html, $this->fallbackProperty, $this->fallbackType);
break;
case 'meta':
$html = $this->machineContent ?? $html;
$html = static::htmlMeta($html, $this->fallbackProperty, $this->fallbackType);
break;
default:
// Default $displayType = 'inline'
$html = static::htmlScope($this->fallbackType) . ' ' . static::htmlProperty($this->fallbackProperty);
break;
}
} else {
/*
* Process and return the HTML in an automatic way,
* with the $Property expected Types and display everything in the right way,
* check if the Property is 'nested' or must be rendered in a metadata tag
*/
switch (static::getExpectedDisplayType($this->fallbackType, $this->fallbackProperty)) {
case 'meta':
// Check if a $content is available, otherwise fallback to an 'inline' display Type
if ($this->content !== null) {
$html = $this->machineContent ?? $this->content;
$html = static::htmlMeta($html, $this->fallbackProperty, $this->fallbackType);
} else {
$html = static::htmlScope($this->fallbackType) . ' ' . static::htmlProperty($this->fallbackProperty);
}
break;
default:
/*
* Default expected display type = 'normal'
* Check if a $content is available,
* otherwise fallback to an 'inline' display Type
*/
if ($this->content !== null) {
$html = static::htmlSpan($this->content, $this->fallbackProperty);
$html = static::htmlSpan($html, '', $this->fallbackType);
} else {
$html = static::htmlScope($this->fallbackType) . ' ' . static::htmlProperty($this->fallbackProperty);
}
break;
}
}
} elseif (!$this->fallbackProperty && $this->fallbackType !== null) {
$html = static::htmlScope($this->fallbackType);
}
// Reset params
$this->resetParams();
return $html;
}