Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Form/Dto/MetaDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

namespace ChamberOrchestra\CmsBundle\Form\Dto;

use ChamberOrchestra\Meta\Entity\Helper\RobotsBehaviour;
use Symfony\Component\HttpFoundation\File\File;

class MetaDto extends AbstractDto
{
public ?string $title = null;
/** @phpstan-ignore class.notFound */
public ?\ChamberOrchestra\MetaBundle\Entity\Helper\RobotsBehaviour $robotsBehaviour = null;
public ?RobotsBehaviour $robotsBehaviour = null;
public ?string $metaTitle = null;
public ?string $metaDescription = null;
public ?string $metaKeywords = null;
Expand Down
14 changes: 7 additions & 7 deletions src/Form/Type/MetaType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace ChamberOrchestra\CmsBundle\Form\Type;

use ChamberOrchestra\CmsBundle\Form\Dto\MetaDto;
use ChamberOrchestra\MetaBundle\Entity\Helper\RobotsBehaviour;
use ChamberOrchestra\Meta\Entity\Helper\RobotsBehaviour;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EnumType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
Expand Down Expand Up @@ -55,13 +55,13 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
],
])
->add('robotsBehaviour', EnumType::class, [
'class' => RobotsBehaviour::class, // @phpstan-ignore class.notFound
'class' => RobotsBehaviour::class,
'required' => true,
'choice_label' => static fn (RobotsBehaviour $case): string => match ($case) { // @phpstan-ignore class.notFound, match.unhandled
RobotsBehaviour::IndexFollow => 'robots_behaviour.indexfollow', // @phpstan-ignore class.notFound
RobotsBehaviour::IndexNoFollow => 'robots_behaviour.indexnofollow', // @phpstan-ignore class.notFound
RobotsBehaviour::NoIndexFollow => 'robots_behaviour.noindexfollow', // @phpstan-ignore class.notFound
RobotsBehaviour::NoIndexNoFollow => 'robots_behaviour.noindexnofollow', // @phpstan-ignore class.notFound
'choice_label' => static fn (RobotsBehaviour $case): string => match ($case) {
RobotsBehaviour::IndexFollow => 'robots_behaviour.indexfollow',
RobotsBehaviour::IndexNoFollow => 'robots_behaviour.indexnofollow',
RobotsBehaviour::NoIndexFollow => 'robots_behaviour.noindexfollow',
RobotsBehaviour::NoIndexNoFollow => 'robots_behaviour.noindexnofollow',
},
'constraints' => [
new NotBlank(),
Expand Down
42 changes: 31 additions & 11 deletions src/Processor/Utils/CrudUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use ChamberOrchestra\CmsBundle\Form\Dto\DtoInterface;
use ChamberOrchestra\CmsBundle\Processor\Instantiator;
use ChamberOrchestra\CmsBundle\Processor\Reflector;
use ChamberOrchestra\MetaBundle\Entity\MetaInterface;
use ChamberOrchestra\Meta\Entity\MetaTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Util\ClassUtils;
Expand Down Expand Up @@ -147,7 +147,7 @@ public function sync(object $source, object $target): void
$this->setPropertyValue($target, $name, $sourceValue);
}

if ($target instanceof MetaInterface) { // @phpstan-ignore class.notFound
if (\in_array(MetaTrait::class, $this->classUsesRecursive($target::class), true)) {
$refl = $this->reflector->create($target);
$props = $refl->getAccessibleProperties();

Expand All @@ -166,34 +166,35 @@ public function sync(object $source, object $target): void
return null;
};

if (!$target->getTitle()) { // @phpstan-ignore class.notFound
$titleProp = $refl->getAccessibleProperty('title');
if (empty($titleProp->getValue($target))) {
$value = $getFirstNonEmptyValue('name');
if ($value) {
$metaTitleProp = $refl->getAccessibleProperty('title');
$metaTitleProp->setValue($target, $value);
$titleProp->setValue($target, $value);
}
}

if (!$target->getMetaTitle()) { // @phpstan-ignore class.notFound
$metaTitleProp = $refl->getAccessibleProperty('metaTitle');
if (empty($metaTitleProp->getValue($target))) {
$value = $getFirstNonEmptyValue('title', 'name');
if ($value) {
$metaTitleProp = $refl->getAccessibleProperty('metaTitle');
$metaTitleProp->setValue($target, $value);
}
}

if (!$target->getMetaDescription()) { // @phpstan-ignore class.notFound
$metaDescProp = $refl->getAccessibleProperty('metaDescription');
if (empty($metaDescProp->getValue($target))) {
$value = $getFirstNonEmptyValue('description');
if ($value) {
/** @var string $valueStr */
$valueStr = $value;
$value = (string) new UnicodeString(\strip_tags($valueStr))->truncate(255);
$metaDescProp = $refl->getAccessibleProperty('metaDescription');
$metaDescProp->setValue($target, $value);
}
}

if (!$target->getMetaImage()) { // @phpstan-ignore class.notFound
$metaImageProp = $refl->getAccessibleProperty('metaImage');
if (empty($metaImageProp->getValue($target))) {
foreach ($props as $prop) {
if (!\str_contains(\mb_strtolower($prop->getName()), 'image')) {
continue;
Expand All @@ -206,7 +207,6 @@ public function sync(object $source, object $target): void
$image = $prop->getValue($target);
if ($image instanceof File) {
$newFile = $this->copyFile($image);
$metaImageProp = $refl->getAccessibleProperty('metaImage');
$metaImageProp->setValue($target, $newFile);
break;
}
Expand Down Expand Up @@ -412,6 +412,26 @@ private function getIntersectedProperties(object $source, object $target): array
return \array_values(\array_intersect($sourceProperties, $targetProperties));
}

/**
* @param class-string $class
*
* @return array<class-string, class-string>
*/
private function classUsesRecursive(string $class): array
{
$traits = [];
do {
/** @var array<class-string, class-string> $classUses */
$classUses = \class_uses($class) ?: [];
$traits = \array_merge($classUses, $traits);
} while ($class = \get_parent_class($class));
foreach ($traits as $trait) {
$traits = \array_merge($this->classUsesRecursive($trait), $traits);
}

return $traits;
}

public function copyFile(File $file): File
{
$originalPath = $file->getRealPath() ?: $file->getPathname();
Expand Down
7 changes: 1 addition & 6 deletions src/Resources/assets/js/plugins/menuSearch.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
'use strict';
import '../jquery-global';
import $ from 'jquery';
import select2Init from 'select2/dist/js/select2';
import 'select2/dist/js/select2';
import observer from "../../component/observer";

// Select2 UMD CommonJS branch exports a factory function — call it to register $.fn.select2
if (typeof select2Init === 'function') {
select2Init(window, $);
}

$.fn.select2.defaults.set("theme", "bootstrap-5");

const Select = {
Expand Down
7 changes: 1 addition & 6 deletions src/Resources/assets/js/select2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@
import '../jquery-global';
import './index.scss';
import $ from 'jquery';
import select2Init from 'select2/dist/js/select2';
import 'select2/dist/js/select2';
import observer from "../../component/observer";

// Select2 UMD CommonJS branch exports a factory function — call it to register $.fn.select2
if (typeof select2Init === 'function') {
select2Init(window, $);
}

$.fn.select2.defaults.set("theme", "bootstrap-5");

observer.observe('select:not(.flatpickr-monthDropdown-months):not([readonly]):not(.no-plugin):not(.no-auto-select2)', (el) => {
Expand Down
3 changes: 2 additions & 1 deletion src/Resources/assets/js/select2/theme/bootstrap/layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

// input-group
.input-group .select2-container--bootstrap-5 {
flex-grow: 1;
flex: 1 1 0%;
min-width: 0;
}

// BS5: input-group-prepend removed, use :not(:first-child) selector
Expand Down
15 changes: 15 additions & 0 deletions src/Resources/translations/cms+intl-icu.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,21 @@ security:
email: E-mail
password: Password

meta:
field:
title: Title
metaTitle: Meta Title
metaDescription: Meta Description
metaKeywords: Meta Keywords
metaImage: Meta Image
robotsBehaviour: Robots Behaviour

robots_behaviour:
indexfollow: 'Index, Follow'
indexnofollow: 'Index, No Follow'
noindexfollow: 'No Index, Follow'
noindexnofollow: 'No Index, No Follow'

crud:
flash:
created: Object has been successfully created
Expand Down
8 changes: 5 additions & 3 deletions src/Resources/views/menu/actions.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

{%- macro nav_item(item, attr) -%}

{%- if item.option('icon') -%}
{%- set icon = item.getExtra('icon') -%}

{%- if icon -%}
{%- set attr = attr|merge({
'data-bs-toggle': 'tooltip',
'title': item.name|trans,
Expand All @@ -33,8 +35,8 @@
{%- set attr = attr|merge({class: (attr.class|default('')) ~ ' ' ~ classes|join(' ')}) -%}

<a {{- menu.attributes(attr) -}}>
{%- if item.option('icon') -%}
<i class="far fa-fw {{ item.option('icon') }}"></i>
{%- if icon -%}
<i class="far fa-fw {{ icon }}"></i>
{%- else -%}
{{- item.name|trans -}}
{%- endif -%}
Expand Down
40 changes: 20 additions & 20 deletions src/Resources/views/pagination/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
@var current int
@var pagesCount int
@var elementsCount int,
@var startPage int
@var endPage int
@var start int
@var end int
@var previous int
@var next int
@var pages array
Expand All @@ -12,21 +12,21 @@
{%- if pagesCount > 1 %}
{%- set _route = app.request.attributes.get("_route") %}
{%- set _route_params = app.request.attributes.get("_route_params")|merge(app.request.query.all()) %}
{%- set _route_params = _route_params|merge({(pageParameter): null}) %}
{%- set _route_params = _route_params|merge({(parameter): null}) %}
<nav class="text-center pagination-container my-0 d-inline-block" {#
#}aria-label="{{- 'pagination.label'|trans -}}">
<ul class="pagination my-0">
{%- if previous is defined %}
{%- if previous is not null %}
<li class="page-item">
{%- if previous > 1 %}
<a class="page-link" rel="prev" aria-label="{{- "pagination.previous"|trans -}}" {#
#}href="{{- path(_route, _route_params|merge({(pageParameter): previous})) -}}">
#}href="{{- path(_route, _route_params|merge({(parameter): previous})) -}}">
<i class="fa fa-fw fa-angle-double-left me-1"></i>
{{- 'pagination.previous'|trans -}}
</a>
{%- else %}
<a class="page-link" rel="prev" aria-label="{{- "pagination.previous"|trans -}}" {#
#}href="{{- path(_route, _route_params|merge({(pageParameter): null})) -}}">
#}href="{{- path(_route, _route_params|merge({(parameter): null})) -}}">
<i class="fa fa-fw fa-angle-double-left me-1"></i>
{{- 'pagination.previous'|trans -}}
</a>
Expand All @@ -41,17 +41,17 @@
</li>
{%- endif %}

{%- if startPage > 1 %}
{%- if start > 1 %}
<li class="page-item">
<a class="page-link" {#
#}href="{{- path(_route, _route_params|merge({(pageParameter): null})) -}}">1</a>
#}href="{{- path(_route, _route_params|merge({(parameter): null})) -}}">1</a>
</li>
{%- if startPage == 3 %}
{%- if start == 3 %}
<li class="page-item">
<a class="page-link" {#
#}href="{{- path(_route, _route_params|merge({(pageParameter): 2})) -}}">2</a>
#}href="{{- path(_route, _route_params|merge({(parameter): 2})) -}}">2</a>
</li>
{%- elseif startPage != 2 %}
{%- elseif start != 2 %}
<li class="page-item disabled">
<a class="page-link" tabindex="-1">
<i class="fa fa-fw fa-ellipsis-h"></i>
Expand All @@ -65,10 +65,10 @@
<li class="page-item">
{%- if page > 1 %}
<a class="page-link" {#
#}href="{{- path(_route, _route_params|merge({(pageParameter): page})) -}}">{{- page -}}</a>
#}href="{{- path(_route, _route_params|merge({(parameter): page})) -}}">{{- page -}}</a>
{%- else %}
<a class="page-link" {#
#}href="{{- path(_route, _route_params|merge({(pageParameter): null})) -}}">{{- page -}}</a>
#}href="{{- path(_route, _route_params|merge({(parameter): null})) -}}">{{- page -}}</a>
{%- endif %}
</li>
{%- else %}
Expand All @@ -81,9 +81,9 @@
{%- endif %}
{%- endfor %}

{%- if pagesCount > endPage %}
{%- if pagesCount > (endPage + 1) %}
{%- if pagesCount > (endPage + 2) %}
{%- if pagesCount > end %}
{%- if pagesCount > (end + 1) %}
{%- if pagesCount > (end + 2) %}
<li class="page-item disabled">
<a class="page-link">
<i class="fa fa-fw fa-ellipsis-h"></i>
Expand All @@ -92,24 +92,24 @@
{%- else %}
<li class="page-item">
<a class="page-link" {#
#}href="{{- path(_route, _route_params|merge({(pageParameter): (pagesCount - 1)})) -}}">
#}href="{{- path(_route, _route_params|merge({(parameter): (pagesCount - 1)})) -}}">
{{- pagesCount - 1 -}}
</a>
</li>
{%- endif %}
{%- endif %}
<li class="page-item">
<a class="page-link" {#
#}href="{{- path(_route, _route_params|merge({(pageParameter): pagesCount})) -}}">
#}href="{{- path(_route, _route_params|merge({(parameter): pagesCount})) -}}">
{{- pagesCount -}}
</a>
</li>
{%- endif %}

{%- if next is defined %}
{%- if next is not null %}
<li class="page-item">
<a rel="next" class="page-link" aria-label="{{- "pagination.next"|trans -}}" {#
#}href="{{- path(_route, _route_params|merge({(pageParameter): next})) -}}">
#}href="{{- path(_route, _route_params|merge({(parameter): next})) -}}">
{{- 'pagination.next'|trans -}}
<i class="fa fa-fw fa-angle-double-right ms-1"></i>
</a>
Expand Down