Skip to content

Commit

Permalink
Added Authors tab
Browse files Browse the repository at this point in the history
  • Loading branch information
kisztof committed Oct 30, 2023
1 parent 9d8cd93 commit c3f6a01
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 74 deletions.
16 changes: 8 additions & 8 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9036,27 +9036,27 @@ parameters:
path: src/lib/Tab/Event/TabViewRenderEvent.php

-
message: "#^Method Ibexa\\\\AdminUi\\\\Tab\\\\LocationView\\\\ContentTab\\:\\:loadContentLanguages\\(\\) return type has no value type specified in iterable type array\\.$#"
message: "#^Method Ibexa\\\\AdminUi\\\\Tab\\\\LocationView\\\\AuthorsTab\\:\\:supplyCreator\\(\\) has parameter \\$parameters with generic class ArrayObject but does not specify its types\\: TKey, TValue$#"
count: 1
path: src/lib/Tab/LocationView/ContentTab.php
path: src/lib/Tab/LocationView/AuthorsTab.php

-
message: "#^Access to protected property Ibexa\\\\AdminUi\\\\UI\\\\Value\\\\ObjectState\\\\ObjectState\\:\\:\\$objectStateGroup\\.$#"
message: "#^Method Ibexa\\\\AdminUi\\\\Tab\\\\LocationView\\\\AuthorsTab\\:\\:supplyLastContributor\\(\\) has parameter \\$parameters with generic class ArrayObject but does not specify its types\\: TKey, TValue$#"
count: 1
path: src/lib/Tab/LocationView/DetailsTab.php
path: src/lib/Tab/LocationView/AuthorsTab.php

-
message: "#^Method Ibexa\\\\AdminUi\\\\Tab\\\\LocationView\\\\DetailsTab\\:\\:supplyCreator\\(\\) has parameter \\$parameters with generic class ArrayObject but does not specify its types\\: TKey, TValue$#"
message: "#^Method Ibexa\\\\AdminUi\\\\Tab\\\\LocationView\\\\ContentTab\\:\\:loadContentLanguages\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Tab/LocationView/DetailsTab.php
path: src/lib/Tab/LocationView/ContentTab.php

-
message: "#^Method Ibexa\\\\AdminUi\\\\Tab\\\\LocationView\\\\DetailsTab\\:\\:supplyFormLocationUpdate\\(\\) has parameter \\$parameters with generic class ArrayObject but does not specify its types\\: TKey, TValue$#"
message: "#^Access to protected property Ibexa\\\\AdminUi\\\\UI\\\\Value\\\\ObjectState\\\\ObjectState\\:\\:\\$objectStateGroup\\.$#"
count: 1
path: src/lib/Tab/LocationView/DetailsTab.php

-
message: "#^Method Ibexa\\\\AdminUi\\\\Tab\\\\LocationView\\\\DetailsTab\\:\\:supplyLastContributor\\(\\) has parameter \\$parameters with generic class ArrayObject but does not specify its types\\: TKey, TValue$#"
message: "#^Method Ibexa\\\\AdminUi\\\\Tab\\\\LocationView\\\\DetailsTab\\:\\:supplyFormLocationUpdate\\(\\) has parameter \\$parameters with generic class ArrayObject but does not specify its types\\: TKey, TValue$#"
count: 1
path: src/lib/Tab/LocationView/DetailsTab.php

Expand Down
9 changes: 7 additions & 2 deletions src/bundle/Resources/translations/ibexa_locationview.en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,14 @@
<target state="new">Visibility</target>
<note>key: tab.locations.visibility</note>
</trans-unit>
<trans-unit id="d1b8c4b5f1920ea90e6b4e1376a3e8167f2ef21a" resname="tab.name.authors">
<source>Authors</source>
<target state="new">Authors</target>
<note>key: tab.name.authors</note>
</trans-unit>
<trans-unit id="5d92b84a6c78bd443010f172c47d01ce0dacacd7" resname="tab.name.details">
<source>Details</source>
<target state="new">Details</target>
<source>Technical Details</source>
<target state="new">Technical Details</target>
<note>key: tab.name.details</note>
</trans-unit>
<trans-unit id="bc992b410ec56cce18c994806d7518fd47da2caa" resname="tab.name.locations">
Expand Down
10 changes: 10 additions & 0 deletions src/bundle/Resources/translations/messages.en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@
<target state="new">Username</target>
<note>key: authentication.username</note>
</trans-unit>
<trans-unit id="61592766b16351f37d5ed4d286a6a789d4ee01ab" resname="autocomplete.no_results">
<source>No suggestions available.</source>
<target state="new">No suggestions available.</target>
<note>key: autocomplete.no_results</note>
</trans-unit>
<trans-unit id="9909b3aba5a51f5fd34ba6c9fdba12115ced5564" resname="autocomplete.view_all_results">
<source>View all results</source>
<target state="new">View all results</target>
<note>key: autocomplete.view_all_results</note>
</trans-unit>
<trans-unit id="b84cc93e7b7f2a9eb0be3e95db4ffde11a97a520" resname="back.to.top">
<source>Go to top</source>
<target state="new">Go to top</target>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{% trans_default_domain 'ibexa_locationview' %}

{% set creator_name %}
{% if creator is not empty %}
{% include '@ibexadesign/ui/component/user/user.html.twig' with { user: creator } only %}
{% else %}
{{ 'tab.details.creator.not_found'|trans|desc('Can\'t fetch creator') }}
{% endif %}
{% endset %}

{% set last_contributor_name %}
{% if last_contributor is not empty %}
{% include '@ibexadesign/ui/component/user/user.html.twig' with { user: last_contributor } only %}
{% else %}
{{ 'tab.details.last_contributor.not_found'|trans|desc('Can\'t fetch last contributor') }}
{% endif %}
{% endset %}

{% set content_details_items = [
{
label: 'tab.details.creator'|trans()|desc('Creator'),
content: creator_name,
},
{
label: 'tab.details.last_contributor'|trans()|desc('Last contributor'),
content: last_contributor_name,
}
] %}

{% include '@ibexadesign/ui/component/details/details.html.twig' with {
headline: 'tab.details.content_details'|trans()|desc('Content details'),
items: content_details_items,
} only %}

{% set technical_details_items = [
{
label: 'tab.details.content_id'|trans()|desc('Content ID'),
content: content_info.id,
},
{
label: 'tab.details.location_id'|trans()|desc('Location ID'),
content: location.id,
}
] %}
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,7 @@
{% endfor %}
{% endset %}

{% set creator_name %}
{% if creator is not empty %}
{% include '@ibexadesign/ui/component/user/user.html.twig' with { user: creator } only %}
{% else %}
{{ 'tab.details.creator.not_found'|trans|desc('Can\'t fetch creator') }}
{% endif %}
{% endset %}

{% set last_contributor_name %}
{% if last_contributor is not empty %}
{% include '@ibexadesign/ui/component/user/user.html.twig' with { user: last_contributor } only %}
{% else %}
{{ 'tab.details.last_contributor.not_found'|trans|desc('Can\'t fetch last contributor') }}
{% endif %}
{% endset %}

{% set content_details_items = [
{
label: 'tab.details.creator'|trans()|desc('Creator'),
content: creator_name,
},
{
label: 'tab.details.last_contributor'|trans()|desc('Last contributor'),
content: last_contributor_name,
},
{
label: 'tab.details.published_version'|trans()|desc('Published version'),
content: version_info.versionNo,
Expand Down
136 changes: 136 additions & 0 deletions src/lib/Tab/LocationView/AuthorsTab.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\AdminUi\Tab\LocationView;

use ArrayObject;
use Ibexa\AdminUi\Specification\UserExists;
use Ibexa\AdminUi\UI\Dataset\DatasetFactory;
use Ibexa\Contracts\AdminUi\Tab\AbstractEventDispatchingTab;
use Ibexa\Contracts\AdminUi\Tab\OrderedTabInterface;
use Ibexa\Contracts\Core\Repository\SectionService;
use Ibexa\Contracts\Core\Repository\UserService;
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
use Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo;
use JMS\TranslationBundle\Annotation\Desc;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;

class AuthorsTab extends AbstractEventDispatchingTab implements OrderedTabInterface
{
public const URI_FRAGMENT = 'ibexa-tab-location-view-authors';

protected UserService $userService;

protected SectionService $sectionService;

protected DatasetFactory $datasetFactory;

/**
* @param \Twig\Environment $twig
* @param \Symfony\Contracts\Translation\TranslatorInterface $translator
* @param \Ibexa\Contracts\Core\Repository\SectionService $sectionService
* @param \Ibexa\Contracts\Core\Repository\UserService $userService
* @param \Ibexa\AdminUi\UI\Dataset\DatasetFactory $datasetFactory
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $eventDispatcher
*/
public function __construct(
Environment $twig,
TranslatorInterface $translator,
SectionService $sectionService,
UserService $userService,
DatasetFactory $datasetFactory,
EventDispatcherInterface $eventDispatcher
) {
parent::__construct($twig, $translator, $eventDispatcher);

$this->sectionService = $sectionService;
$this->userService = $userService;
$this->datasetFactory = $datasetFactory;
}

/**
* @return string
*/
public function getIdentifier(): string
{
return 'authors';
}

/**
* @return string
*/
public function getName(): string
{
/** @Desc("authors") */
return $this->translator->trans('tab.name.authors', [], 'ibexa_locationview');
}

/**
* @return int
*/
public function getOrder(): int
{
return 200;
}

/**
* {@inheritdoc}
*/
public function getTemplate(): string
{
return '@ibexadesign/content/tab/authors.html.twig';
}

/**
* {@inheritdoc}
*/
public function getTemplateParameters(array $contextParameters = []): array
{
/** @var \Ibexa\Contracts\Core\Repository\Values\Content\Content $content */
$content = $contextParameters['content'];

$versionInfo = $content->getVersionInfo();
$contentInfo = $versionInfo->getContentInfo();

$viewParameters = new ArrayObject([
'content_info' => $contentInfo,
'version_info' => $versionInfo,
]);

$this->supplyCreator($viewParameters, $contentInfo);
$this->supplyLastContributor($viewParameters, $versionInfo);

return array_replace($contextParameters, $viewParameters->getArrayCopy());
}

/**
* @param \ArrayObject $parameters
* @param \Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo $versionInfo
*/
private function supplyLastContributor(ArrayObject $parameters, VersionInfo $versionInfo): void
{
$parameters['last_contributor'] = null;
if ((new UserExists($this->userService))->isSatisfiedBy($versionInfo->creatorId)) {
$parameters['last_contributor'] = $this->userService->loadUser($versionInfo->creatorId);
}
}

/**
* @param \ArrayObject $parameters
* @param \Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo $contentInfo
*/
private function supplyCreator(ArrayObject $parameters, ContentInfo $contentInfo): void
{
$parameters['creator'] = null;
if ((new UserExists($this->userService))->isSatisfiedBy($contentInfo->ownerId)) {
$parameters['creator'] = $this->userService->loadUser($contentInfo->ownerId);
}
}
}
45 changes: 5 additions & 40 deletions src/lib/Tab/LocationView/DetailsTab.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Ibexa\AdminUi\Form\Type\Location\LocationAssignSectionType;
use Ibexa\AdminUi\Form\Type\Location\LocationUpdateType;
use Ibexa\AdminUi\Form\Type\ObjectState\ContentObjectStateUpdateType;
use Ibexa\AdminUi\Specification\UserExists;
use Ibexa\AdminUi\UI\Dataset\DatasetFactory;
use Ibexa\Contracts\AdminUi\Tab\AbstractEventDispatchingTab;
use Ibexa\Contracts\AdminUi\Tab\OrderedTabInterface;
Expand All @@ -35,23 +34,15 @@ class DetailsTab extends AbstractEventDispatchingTab implements OrderedTabInterf
{
public const URI_FRAGMENT = 'ibexa-tab-location-view-details';

/** @var \Ibexa\Core\Helper\FieldsGroups\FieldsGroupsList */
protected $fieldsGroupsListHelper;
protected UserService $userService;

/** @var \Ibexa\Contracts\Core\Repository\UserService */
protected $userService;
protected SectionService $sectionService;

/** @var \Ibexa\Contracts\Core\Repository\SectionService */
protected $sectionService;
protected DatasetFactory $datasetFactory;

/** @var \Ibexa\AdminUi\UI\Dataset\DatasetFactory */
protected $datasetFactory;
private FormFactoryInterface $formFactory;

/** @var \Symfony\Component\Form\FormFactoryInterface */
private $formFactory;

/** @var \Ibexa\Contracts\Core\Repository\PermissionResolver */
private $permissionResolver;
private PermissionResolver $permissionResolver;

/**
* @param \Twig\Environment $twig
Expand Down Expand Up @@ -137,8 +128,6 @@ public function getTemplateParameters(array $contextParameters = []): array
$this->supplyObjectStateParameters($viewParameters, $contentInfo);
$this->supplyTranslations($viewParameters, $versionInfo);
$this->supplyFormLocationUpdate($viewParameters, $location);
$this->supplyCreator($viewParameters, $contentInfo);
$this->supplyLastContributor($viewParameters, $versionInfo);
$this->supplySortFieldClauseMap($viewParameters);

return array_replace($contextParameters, $viewParameters->getArrayCopy());
Expand All @@ -162,30 +151,6 @@ private function supplySortFieldClauseMap(ArrayObject $parameters): void
];
}

/**
* @param \ArrayObject $parameters
* @param \Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo $contentInfo
*/
private function supplyCreator(ArrayObject $parameters, ContentInfo $contentInfo): void
{
$parameters['creator'] = null;
if ((new UserExists($this->userService))->isSatisfiedBy($contentInfo->ownerId)) {
$parameters['creator'] = $this->userService->loadUser($contentInfo->ownerId);
}
}

/**
* @param \ArrayObject $parameters
* @param \Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo $versionInfo
*/
private function supplyLastContributor(ArrayObject $parameters, VersionInfo $versionInfo): void
{
$parameters['last_contributor'] = null;
if ((new UserExists($this->userService))->isSatisfiedBy($versionInfo->creatorId)) {
$parameters['last_contributor'] = $this->userService->loadUser($versionInfo->creatorId);
}
}

/**
* @param \ArrayObject $parameters
* @param \Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo $contentInfo
Expand Down

0 comments on commit c3f6a01

Please sign in to comment.