Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-9169: Enable searching by content's name in the Trash #1388

Merged
merged 13 commits into from
Nov 27, 2024
4 changes: 2 additions & 2 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ parameters:
path: src/bundle/Controller/LinkManagerController.php

-
message: "#^Cannot access offset 0 on iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Relation\\>\\.$#"
message: "#^Cannot access offset 0 on iterable\\<int, Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Relation\\>\\.$#"
count: 1
path: src/bundle/Controller/LocationController.php

Expand Down Expand Up @@ -9546,7 +9546,7 @@ parameters:
path: src/lib/UI/Dataset/VersionsDataset.php

-
message: "#^Parameter \\#2 \\$array of function array_map expects array, iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\VersionInfo\\> given\\.$#"
message: "#^Parameter \\#2 \\$array of function array_map expects array, iterable\\<int, Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\VersionInfo\\> given\\.$#"
count: 1
path: src/lib/UI/Dataset/VersionsDataset.php

Expand Down
5 changes: 5 additions & 0 deletions src/bundle/Resources/translations/ibexa_trash.en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@
<target state="new">Any time</target>
<note>key: trash.search.any_time</note>
</trans-unit>
<trans-unit id="c7905f2b692c3d584517c5e6b921771afcc73cf1" resname="trash.search.search_by_content_name">
<source>Search by content name</source>
<target state="new">Search by content name</target>
<note>key: trash.search.search_by_content_name</note>
</trans-unit>
<trans-unit id="c2b2679781ad4a22bb232e2ab34669ffe49c760b" resname="trash.search.section.any">
<source>All</source>
<target state="new">All</target>
Expand Down
53 changes: 30 additions & 23 deletions src/bundle/Resources/views/themes/admin/trash/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,37 @@

{% block content %}
{% set trash_search_params = app.request.get('trash_search') %}
{% set creator = form_search.vars.data ? form_search.vars.data.creator : '' %}
{% set creator_exists = creator is not empty %}

{% set creatorSearch %}
<div class="form-group">
<label class="ibexa-label form-label" for="trash_search_content_type">
{{ 'search.creator_input.placeholder' | trans | desc('Search by creator') }}
</label>
<div class="ibexa-trash-search-form__item ibexa-trash-search-form__item--creator">
<div class="ibexa-trash-search-form__input-wrapper">
<input
type="text"
class="form-control ibexa-input ibexa-input--text ibexa-trash-search-form__input"
data-content-type-identifiers="{{ user_content_type_identifier | join(',') }}"
value="{{ creator_exists ? ibexa_content_name(creator) : '' }}"
{{ creator_exists ? 'disabled' : '' }}
>
<button class="btn ibexa-btn ibexa-btn--ghost ibexa-btn--no-text ibexa-btn--reset-creator">
<svg class="ibexa-icon ibexa-icon--tiny-small ibexa-icon--reset">
<use xlink:href="{{ ibexa_icon_path('discard') }}"></use>
</svg>
</button>
</div>
<ul class="ibexa-trash-search-form__user-list ibexa-trash-search-form__user-list--hidden"></ul>
</div>
</div>
{% endset %}

<div class="ibexa-container">
{% set collapsible_items = [
creatorSearch,
form_row(form_search.content_type, {
'attr': {'class': 'ibexa-trash-search-form__item ibexa-trash-search-form__item--auto-send'}
}),
Expand Down Expand Up @@ -55,28 +83,7 @@
{% trans_default_domain 'ibexa_trash' %}

{% block static_left_input %}
<div class="ibexa-trash-search-form__item ibexa-trash-search-form__item--creator">
{% set creator = form_search.vars.data ? form_search.vars.data.creator : '' %}
{% set creator_exists = creator is not empty ? true : false %}

<div class="ibexa-trash-search-form__input-wrapper">
<input
type="text"
class="form-control ibexa-input ibexa-input--text ibexa-trash-search-form__input"
data-content-type-identifiers="{{ user_content_type_identifier|join(',') }}"
value="{{ creator_exists ? ibexa_content_name(creator) }}"
placeholder="{{ 'search.creator_input.placeholder'|trans|desc('Search by creator') }}"
{{ creator_exists ? 'disabled' }}
>
<button class="btn ibexa-btn ibexa-btn--ghost ibexa-btn--no-text ibexa-btn--reset-creator">
<svg class="ibexa-icon ibexa-icon--tiny-small ibexa-icon--reset">
<use xlink:href="{{ ibexa_icon_path('discard') }}"></use>
</svg>
</button>
</div>
<ul class="ibexa-trash-search-form__user-list ibexa-trash-search-form__user-list--hidden"></ul>
</div>

{{ form_widget(form_search.content_name) }}
{{ form_widget(form_search.creator, {'attr': {'hidden': 'hidden'}}) }}
{{ form_widget(form_search.sort, {'attr': {'hidden': 'hidden'}}) }}
{{ form_widget(form_search.trashed_interval, {'attr': {'hidden': 'hidden'}}) }}
Expand Down Expand Up @@ -328,7 +335,7 @@
} %}
{% endif %}
{% include '@ibexadesign/trash/modal/empty_trash_confirmation.html.twig' with {'form': form_trash_empty, 'trash_items_count': pager.nbResults} %}
</div>
</div>
{% endblock %}

{% block react_modules %}
Expand Down
19 changes: 16 additions & 3 deletions src/lib/Form/Data/Search/TrashSearchData.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class TrashSearchData
/** @var array|null */
private $sort;

private ?string $contentName;

public function __construct(
?int $limit = 10,
?int $page = 1,
Expand All @@ -46,6 +48,7 @@ public function __construct(
?string $trashed = null,
?array $trashedInterval = [],
?User $creator = null,
?string $contentName = null,
?array $sort = ['field' => 'trashed', 'direction' => 0]
) {
$this->limit = $limit;
Expand All @@ -55,6 +58,7 @@ public function __construct(
$this->trashed = $trashed;
$this->trashedInterval = $trashedInterval;
$this->creator = $creator;
$this->contentName = $contentName;
$this->sort = $sort;
}

Expand Down Expand Up @@ -128,6 +132,16 @@ public function setCreator(?User $creator): void
$this->creator = $creator;
}

public function getContentName(): ?string
{
return $this->contentName;
}

public function setContentName(?string $contentName): void
{
$this->contentName = $contentName;
}

public function getSort(): ?array
{
return $this->sort;
Expand All @@ -138,20 +152,19 @@ public function setSort(?array $sort): void
$this->sort = $sort;
}

/**
* @return bool
*/
public function isFiltered(): bool
{
$contentType = $this->getContentType();
$section = $this->getSection();
$trashed = $this->getTrashedInterval();
$creator = $this->getCreator();
$contentName = $this->getContentName();

return
null !== $contentType ||
null !== $section ||
null !== $creator ||
null !== $contentName ||
!empty($trashed);
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/lib/Form/Type/Search/TrashSearchType.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\OptionsResolver\OptionsResolver;
Expand Down Expand Up @@ -57,6 +58,12 @@ public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('page', HiddenType::class)
->add('content_name', TextType::class, [
'required' => false,
'attr' => [
'placeholder' => /** @Desc("Search by content name") */ 'trash.search.search_by_content_name',
],
])
->add('content_type', ChoiceType::class, [
'choice_loader' => $this->searchContentTypeChoiceLoader,
'choice_label' => 'name',
Expand Down
4 changes: 4 additions & 0 deletions src/lib/QueryType/TrashSearchQueryType.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ protected function addCriteria(TrashSearchData $searchData, Query $query): void
);
}

if ($searchData->getContentName() !== null) {
$criteria[] = new Criterion\ContentName($searchData->getContentName());
}

if (!empty($criteria)) {
$query->filter = new Criterion\LogicalAnd($criteria);
}
Expand Down
Loading