Unknown Property – yii\base\UnknownPropertyException
Setting unknown property: yii\bootstrap5\Modal::aria-labelledby

<?php

use yii\bootstrap5\Modal;
use yii\base\Widget;

class ModalJQry extends Widget
{
    /**
     * @var array Options for modal configuration and container HTML attributes.
     * Supported keys include:
     * - 'id' => string, modal HTML id (generated if not provided)
     * - 'title' => string, modal header title (overrides $this->title)
     * - 'size' => string, modal size (overrides $this->size)
     * - 'backdrop' => bool|string, Bootstrap modal backdrop option
     * - 'keyboard' => bool, Bootstrap modal keyboard option
     * - 'centered' => bool, Bootstrap modal centered option
     * - 'scrollable' => bool, Bootstrap modal scrollable option
     * - 'fade' => bool, Bootstrap modal fade animation option
     * - 'options' => array, HTML attributes for the modal container tag (e.g. ['class' => 'custom-class'])
     */
    public array $options = [];

    /**
     * @var string Default modal title (overridden by $options['title'] if set)
     */
    public string $title = 'Modal Title';

    /**
     * @var string Default modal size (overridden by $options['size'] if set)
     * Use Modal::SIZE_DEFAULT, Modal::SIZE_LARGE, Modal::SIZE_SMALL
     */
    public string $size = Modal::SIZE_LARGE;

    // Add any other widget properties you need here (e.g. $formModel, etc.)

    /**
     * Runs the widget and renders the Bootstrap 5 modal begin() call.
     * Remember to call Modal::end() after outputting modal content.
     */
    public function run(): void
    {
        // Determine modal ID, generate one if not provided
        $id = $this->options['id'] ?? $this->getId();

        // Determine modal title and size, allowing user to override via $options
        $modalTitle = $this->options['title'] ?? $this->title;
        $modalSize = $this->options['size'] ?? $this->size;

        // Extract 'options' (HTML attributes for modal container) or empty array
        $htmlOptions = $this->options['options'] ?? [];

        // Prepare default classes to ensure Bootstrap modal styles and smooth fade + your custom class 'square'
        $defaultClasses = ['modal', 'fade', 'square'];

        // Merge with any classes user provided in $htmlOptions['class']
        $existingClasses = [];

        if (isset($htmlOptions['class'])) {
            if (is_array($htmlOptions['class'])) {
                $existingClasses = $htmlOptions['class'];
            } elseif (is_string($htmlOptions['class'])) {
                $existingClasses = preg_split('/\s+/', trim($htmlOptions['class']));
            }
        }

        $combinedClasses = array_unique(array_merge($defaultClasses, $existingClasses));
        $htmlOptions['class'] = implode(' ', $combinedClasses);

        // Prepare modal config: include all options from $this->options except 'id', 'title', 'size', and 'options' which we handled separately
        $modalOptions = $this->options;
        unset($modalOptions['id'], $modalOptions['title'], $modalOptions['size'], $modalOptions['options']);

        // Merge with our base configuration
        $config = array_merge([
            'id' => $id,
            'title' => $modalTitle,
            'size' => $modalSize,
            'options' => $htmlOptions,
        ], $modalOptions);

        // Begin the modal widget
        Modal::begin($config);

        // Note: The modal content should be rendered by the user of this widget,
        // and Modal::end() should be called afterward to close the modal HTML.
    }
}