Learn more about CSS Classes
*/
public string $cssClasses;
/**
* @label With Gutenberg Block
* @instructions If checked, a separate gutenberg block for this view will be available
* @a-pro The field must be not required or have default value!
*/
public bool $isHasGutenbergBlock;
/**
* @item \org\wplake\acf_views\AcfGroups\Item
* @var Item[]
* @label Fields
* @instructions Fields of this view. Tip : hover mouse on the field number column and drag to reorder
* @button_label Add Field
* @a-no-accordion 1
*/
public array $items;
/**
* @a-type tab
* @label Markup
*/
public bool $markupTab;
/**
* @a-type textarea
* @new_lines br
* @label Markup
* @instructions Output preview of HTML markup generated. Important! Publish or Update your view to see the latest markup
*/
public string $markup;
/**
* @a-type textarea
* @label Custom Markup
* @instructions Warning : for users familiar with HTML. Write your own HTML markup with full control over how your view will look. You can copy the Markup field output and make your changes.
Make sure you've kept all variables (look like '$name$') and wrappers (look like HTML comments), otherwise field values won't be inserted.
Important! This field will not be updated automatically when you add or remove fields, so you have to update this field manually to reflect the new changes (you could see the Markup field for assistance)
* @a-pro The field must be not required or have default value!
*/
public string $customMarkup;
/**
* @a-type textarea
* @label Custom Markup Variables
* @instructions You can add custom variables to the custom markup using this PHP code snippet.
The snippet must return an associative array of values, where keys are variable names. These variables will be available in the custom markup within brackets, like '{VARIABLE_NAME}'.
In the snippet pre-defined following variables : '$_objectId' (current data post), '$_viewId' (current view id),'$_fields' (an associative field values array, where keys are field identifiers)
* @default_value You should use '.acf-view--id--X' selector to match the current view (where 'X' means the current view id) OR you can use magic '#view' alias, that will be automatically replaced with target '.acf-view--id--X' (it means you can have '#view .acf-view__field' as a selector, and it'll work right)
*/
public string $cssCode;
/**
* @a-type textarea
* @label JS Code
* @instructions Add your own Javascript to your view. This will be added within <script></script> tags ONLY to pages that have this view and also will be wrapped into an anonymous function to avoid name conflicts
*/
public string $jsCode;
/**
* @a-type tab
* @label Preview
*/
public bool $previewTab;
/**
* @a-type post_object
* @return_format 1
* @allow_null 1
* @label Preview Object
* @instructions Select a data object (which field values will be used) and press the 'Update' button to see the final markup in the preview
*/
public int $previewPost;
/**
* @label Preview
* @instructions Here you can see the preview of the view and play with CSS rules. Important! Press the 'Update' button after changes to see the latest markup here.
Your changes to the preview won't be applied to the view automatically, if you want to keep them copy amended CSS to the 'CSS Code' field and press the 'Update' button.
Note : except the view styles the preview contains also styles of your homepage to give the preview the same look as the view will have on your front (some differences are still possible).
* @placeholder Loading... Please wait a few seconds
* @disabled 1
*/
public string $preview;
private array $fieldsMeta;
public function __construct(CreatorInterface $creator)
{
parent::__construct($creator);
$this->fieldsMeta = [];
}
public static function getGroupInfo(): array
{
return array_merge(parent::getGroupInfo(), [
'title' => 'View settings',
]);
}
public function setFieldsMeta(array $fieldsMeta = [], bool $isForce = false): void
{
if ($fieldsMeta ||
$isForce) {
$this->fieldsMeta = $fieldsMeta;
return;
}
foreach ($this->items as $item) {
$fieldId = $item->field->getAcfFieldId();
$this->fieldsMeta[$fieldId] = new FieldMeta($fieldId);
}
}
public function getFieldsMeta(): array
{
return $this->fieldsMeta;
}
public function getCssCode(bool $isMinify = true): string
{
$cssCode = $this->cssCode;
if ($isMinify) {
// remove all CSS comments
$cssCode = preg_replace('|\/\*(.?)+\*\/|', '', $cssCode);
// 'minify' CSS
$cssCode = str_replace(["\t", "\n", "\r"], '', $cssCode);
$cssCode = str_replace('#view ', sprintf('.acf-view--id--%s ', $this->getSource()), $cssCode);
$cssCode = str_replace('#view{', sprintf('.acf-view--id--%s{', $this->getSource()), $cssCode);
$cssCode = trim($cssCode);
}
return $cssCode;
}
}