add color property in Navigation
add badge with navigation color in admin views
This commit is contained in:
parent
b38fe0fe00
commit
6a5c5d899f
|
@ -108,6 +108,7 @@ class NavigationAdminController extends CrudController
|
||||||
|
|
||||||
->setField('index', 'Label', Field\TextField::class, [
|
->setField('index', 'Label', Field\TextField::class, [
|
||||||
'property' => 'label',
|
'property' => 'label',
|
||||||
|
'view' => '@Core/site/navigation_admin/field/label.html.twig',
|
||||||
'attr' => ['class' => 'miw-200'],
|
'attr' => ['class' => 'miw-200'],
|
||||||
])
|
])
|
||||||
->setField('index', 'Domain', Field\ButtonField::class, [
|
->setField('index', 'Domain', Field\ButtonField::class, [
|
||||||
|
|
|
@ -42,6 +42,9 @@ class Navigation implements EntityInterface
|
||||||
#[ORM\Column(type: 'string', length: 10)]
|
#[ORM\Column(type: 'string', length: 10)]
|
||||||
protected $locale = 'en';
|
protected $locale = 'en';
|
||||||
|
|
||||||
|
#[ORM\Column(type: 'string', length: 7, nullable: true)]
|
||||||
|
protected $color = null;
|
||||||
|
|
||||||
#[ORM\Column(type: 'integer', nullable: true)]
|
#[ORM\Column(type: 'integer', nullable: true)]
|
||||||
protected $sortOrder;
|
protected $sortOrder;
|
||||||
|
|
||||||
|
@ -237,4 +240,16 @@ class Navigation implements EntityInterface
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setColor(string $color): self
|
||||||
|
{
|
||||||
|
$this->color = $color;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getColor(): string
|
||||||
|
{
|
||||||
|
return $this->color;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
use Symfony\Component\Validator\Constraints\Length;
|
use Symfony\Component\Validator\Constraints\Length;
|
||||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\ColorType;
|
||||||
|
|
||||||
class NavigationType extends AbstractType
|
class NavigationType extends AbstractType
|
||||||
{
|
{
|
||||||
|
@ -44,6 +45,20 @@ class NavigationType extends AbstractType
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$builder->add(
|
||||||
|
'color',
|
||||||
|
ColorType::class,
|
||||||
|
[
|
||||||
|
'label' => 'Color',
|
||||||
|
'required' => true,
|
||||||
|
'attr' => [
|
||||||
|
],
|
||||||
|
'constraints' => [
|
||||||
|
new NotBlank(),
|
||||||
|
],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
$builder->add(
|
$builder->add(
|
||||||
'domain',
|
'domain',
|
||||||
TextType::class,
|
TextType::class,
|
||||||
|
|
|
@ -402,6 +402,31 @@ th {
|
||||||
margin-right: 4px;
|
margin-right: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.form-color {
|
||||||
|
display: inline-block;
|
||||||
|
line-height: 0;
|
||||||
|
border-radius: 25%;
|
||||||
|
|
||||||
|
input {
|
||||||
|
padding: 0;
|
||||||
|
border: 0;
|
||||||
|
height: auto;
|
||||||
|
width: 30px;
|
||||||
|
aspect-ratio: 1/1;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge-square {
|
||||||
|
aspect-ratio: 1/1;
|
||||||
|
min-width: 14px;
|
||||||
|
min-height: 14px;
|
||||||
|
vertical-align: middle;
|
||||||
|
padding: 0;
|
||||||
|
aspect-ratio: 1/1;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
#form-main {
|
#form-main {
|
||||||
> .tab-content {
|
> .tab-content {
|
||||||
@media screen and (min-width: 500px) {
|
@media screen and (min-width: 500px) {
|
||||||
|
|
|
@ -7,6 +7,15 @@
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block color_widget %}
|
||||||
|
<div class="form-color-container">
|
||||||
|
<div class="form-color">
|
||||||
|
{%- set type = type|default('color') -%}
|
||||||
|
{{ block('form_widget_simple') }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block file_widget -%}
|
{% block file_widget -%}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12 p-3">
|
<div class="col-12 p-3">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{% for item in ['label', 'locale', 'code'] %}
|
{% for item in ['label', 'locale', 'code', 'color'] %}
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
{{ form_row(form[item]) }}
|
{{ form_row(form[item]) }}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
{% extends '@Core/admin/crud/field/text.html.twig' %}
|
||||||
|
|
||||||
|
{% block value %}
|
||||||
|
{{ navigation_color_badge(entity) }}
|
||||||
|
{{ parent() }}
|
||||||
|
{% endblock %}
|
|
@ -41,6 +41,7 @@
|
||||||
navigation: node.menu.navigation.id,
|
navigation: node.menu.navigation.id,
|
||||||
'data-modal': path('admin_site_node_edit', {entity: node.id}),
|
'data-modal': path('admin_site_node_edit', {entity: node.id}),
|
||||||
}) }}" class="btn btn-sm btn-light mr-1" target="_blank">
|
}) }}" class="btn btn-sm btn-light mr-1" target="_blank">
|
||||||
|
{{ navigation_color_badge(node.menu.navigation) }}
|
||||||
{{ node.label }} ({{ node.menu.navigation.label }})
|
{{ node.label }} ({{ node.menu.navigation.label }})
|
||||||
</a>
|
</a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
navigation: node.menu.navigation.id,
|
navigation: node.menu.navigation.id,
|
||||||
'data-modal': path('admin_site_node_edit', {entity: node.id}),
|
'data-modal': path('admin_site_node_edit', {entity: node.id}),
|
||||||
}) }}" class="btn btn-sm btn-light mr-1">
|
}) }}" class="btn btn-sm btn-light mr-1">
|
||||||
|
{{ navigation_color_badge(node.menu.navigation) }}
|
||||||
{{ node.label }} ({{ node.menu.navigation.label }})
|
{{ node.label }} ({{ node.menu.navigation.label }})
|
||||||
</a>
|
</a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -8,12 +8,14 @@
|
||||||
<div class="crud-header-title">
|
<div class="crud-header-title">
|
||||||
<button type="button" class="btn btn-outline-dark dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
<button type="button" class="btn btn-outline-dark dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||||
<span class="font-weight-bold">
|
<span class="font-weight-bold">
|
||||||
|
{{ navigation_color_badge(navigation) }}
|
||||||
{{ navigation.label }}
|
{{ navigation.label }}
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
<div class="dropdown-menu">
|
<div class="dropdown-menu">
|
||||||
{% for item in navigations %}
|
{% for item in navigations %}
|
||||||
<a href="{{ path('admin_site_tree_navigation', {navigation: item.id}) }}" class="dropdown-item">
|
<a href="{{ path('admin_site_tree_navigation', {navigation: item.id}) }}" class="dropdown-item">
|
||||||
|
{{ navigation_color_badge(item) }}
|
||||||
{{ item.label }}
|
{{ item.label }}
|
||||||
</a>
|
</a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
32
src/core/Twig/Extension/NavigationExtension.php
Normal file
32
src/core/Twig/Extension/NavigationExtension.php
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Core\Twig\Extension;
|
||||||
|
|
||||||
|
use App\Core\Entity\Site\Navigation;
|
||||||
|
use Twig\Extension\AbstractExtension;
|
||||||
|
use Twig\TwigFunction;
|
||||||
|
|
||||||
|
class NavigationExtension extends AbstractExtension
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getFunctions()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
new TwigFunction('navigation_color_badge', [$this, 'navigationColorBadge'], ['is_safe' => ['html']]),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function navigationColorBadge(Navigation $entity): ?string
|
||||||
|
{
|
||||||
|
if (!$entity->getColor()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return sprintf(
|
||||||
|
'<span class="badge badge-square" style="background: %s"> </span>',
|
||||||
|
$entity->getColor()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue