<?php
$translate = $this->plugin('translate');
// Prepare the resource class query.
$ids = isset($query['resource_class_id']) ? $query['resource_class_id'] : [];
if (!is_array($ids)) {
    $ids = [$ids];
}
$ids = array_filter($ids);
if (!$ids) {
    $ids = [null];
}
$optionsQuery = [];
if ($this->status()->isSiteRequest()) {
    if ($this->siteSetting('vocabulary_scope') === 'sitewide') {
        if ('itemSet' === $resourceType) {
            $optionsQuery['site_id_item_sets'] = $this->layout()->site->id();
        } else {
            $optionsQuery['site_id'] = $this->layout()->site->id();
        }
    } elseif ($this->siteSetting('vocabulary_scope') === 'cross-site') {
        $optionsQuery['used'] = true;
    }
}

?>
<div id="resource-class" class="field removable multi-value" role="group" aria-labelledby="by-resource-class-label">
    <div class="field-meta">
        <span id="by-resource-class-label" class="label"><?php echo $translate('Search by class'); ?></span>
        <?php echo $this->hyperlink('', '#', ['class' => 'expand', 'title' => $translate('Expand')]); ?>
        <div class="collapsible">
            <div class="field-description"><?php echo $translate('Searches for resources that are any of these classes.'); ?></div>
        </div>
        <button type="button" class="add-value o-icon-add button" aria-label="<?php echo $translate('Add new class'); ?>" title="<?php echo $translate('Add new class'); ?>"></button>
    </div>
    <div class="inputs">
        <?php foreach ($ids as $id): ?>
        <div class="value">
            <?php echo $this->resourceClassSelect([
                'name' => 'resource_class_id[]',
                'attributes' => [
                    'value' => $id,
                    'aria-labelledby' =>  'by-resource-class-label'
                ],
                'options' => [
                    'query' => $optionsQuery
                ]
            ]); ?>
            <button type="button" class="o-icon-delete remove-value button" aria-label="<?php echo $translate('Remove value'); ?>" title="<?php echo $translate('Remove value'); ?>"></button>
        </div>
        <?php endforeach; ?>
    </div>
</div>
