zf3 navigation for admin, and for client - zend-framework3

How to make navigation for admin and for client?
Is there some value to be add in the bellow code like 'id' or something else ?
Code:
'navigation' => [
'default' => [
[
'label' => 'User',
'route' => 'user',
'pages' => [
[
'label' => 'Login',
'route' => 'user/login',
'action' => 'login',
],
[
'label' => 'Logout',
'route' => 'user/logout',
'action' => 'logout',
],
],
],
],
]

Found it!
'navigation' => [
'default' => [
[
'label' => 'Blog',
'route' => 'blog',
'pages' => [
[
'label' => 'Detail',
'route' => 'blog/detail',
'action' => 'detail',
],
[
'label' => 'Add',
'route' => 'blog/add',
'action' => 'add',
],
[
'label' => 'Edit',
'route' => 'blog/edit',
'action' => 'edit',
],
[
'label' => 'Delete',
'route' => 'blog/delete',
'action' => 'delete',
],
],
],
],
'navigation-admin' => [
[
'label' => 'Blog',
'route' => 'blog',
'pages' => [
[
'label' => 'Detail',
'route' => 'blog/detail',
'action' => 'detail',
],
[
'label' => 'Add',
'route' => 'blog/add',
'action' => 'add',
],
[
'label' => 'Edit',
'route' => 'blog/edit',
'action' => 'edit',
],
[
'label' => 'Delete',
'route' => 'blog/delete',
'action' => 'delete',
],
],
],
],
]
Then you add:
'service_manager' => [
'factories' => [
'navigation-admin' => Service\Factory\NavigationFactory::class ]
],
Create the factory class NavigationFactory that extends Zend\Navigation\Service\DefaultNavigationFactory:
protected function getName()
{
return 'navigation-admin';
}
And in the view just check the user what is and load the navigation:
<?= $this->navigation('navigation-admin')
->menu()
->setMinDepth(0)
->setMaxDepth(0)
->setUlClass('nav navbar-nav')
?>

Related

How to properly use oneOf and anyOf in WP rest schema?

I'm tyring to register_meta as a array with oneOf keyword.
The wp rest schema docs says that we have to use the keyword inside the items array like so:
array(
'type' => 'array',
'items' => array(
'oneOf' => array(
...
),
),
)
But this throws an error saying that we should register with the show_in_rest property, as so:
array(
'type' => 'array',
'show_in_rest' => array(
'schema' => array(
'items' => array(
'oneOf' => array(
...
),
),
),
),
);
But then again another error saying that we have to define the type of the items:
array(
'type' => 'array',
'show_in_rest' => array(
'schema' => array(
'items' => array(
'type' => 'object',
'oneOf' => array(
...
),
),
),
),
);
After that I registered two different objects inside oneOf:
array(
'type' => 'object',
'properties' => array(
'dia' => array(
'type' => 'string',
'format' => 'date',
'name' => 'dia',
'label' => 'Dia',
),
'hora_inicio' => array(
'type' => 'string',
'format' => 'time',
'name' => 'hora_inicio',
'label' => 'Hora inicial',
),
'hora_fim' => array(
'type' => 'string',
'format' => 'time',
'name' => 'hora_fim',
'label' => 'Hora final',
),
),
'name' => 'data_unica',
'title' => 'Data única',
),
array(
'type' => 'object',
'properties' => array(
'periodicidade' => array(
'type' => 'string',
'name' => 'periodicidade',
'label' => 'Periodicidade',
'description' => 'Periodicidade do ciclo',
'enum' => array(
'DIARIO' => 'Diário',
'SEMANAL' => 'Semanal',
'QUINZENAL' => 'Quinzenal',
'MENSAL' => 'Mensal',
),
),
'dia_inicial' => array(
'type' => 'string',
'format' => 'date',
'name' => 'dia_inicial',
'label' => 'Dia inicial',
'description' => 'Dia de início do ciclo',
),
'dia_final' => array(
'type' => 'string',
'format' => 'date',
'name' => 'dia_final',
'label' => 'Dia final',
'description' => 'Dia final do ciclo',
),
'hora_inicial' => array(
'type' => 'string',
'format' => 'time',
'name' => 'hora_inicial',
'label' => 'Hora inicial',
),
'hora_final' => array(
'type' => 'string',
'format' => 'time',
'name' => 'hora_final',
'label' => 'Hora final',
),
),
'name' => 'data_corrente',
'title' => 'Data corrente',
),
when I save the post with this meta object (below) mounted with gutenberg blocks I get a error saying that the object matchs the both schema
Request:
{
"datas": [
{
"dia": "2022-07-14",
"hora_inicio": "20:20",
"hora_fim": "17:20"
}
],
}
Response
{
"code": "rest_one_of_multiple_matches",
"message": "meta.datas[0] matches Data única and Data corrente, but should match only one.",
"data": {
"status": 400
},
"additional_data": [{
"positions": [0, 1]
}]
}
Could someone help me with this?

Overide custom post type slug/permalink

Have this code,
I create a custom post type "Resources"
what I want is to change slug to include only custom taxonamy "resource_types"
resourse/%custom_taxonamy%/%postname%
Now it writes: 'resourse/%resource_types%/%postname%' - where only %postname% changes dynamically based on post name.
'%resource_types%' - it shows as static string
Im missing something, but cant find it.
add_action('init', function () {
register_post_type('resource', [
'labels' => [
'name' => 'Resources',
'singular_name' => 'Resource',
],
'public' => true,
'has_archive' => false,
'supports' => ['title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields'],
'rewrite' => [
'slug' => 'resources/%resource_types%',
'with_front' => true,
],
]);
register_taxonomy('resource_types', 'resource', [
'hierarchical' => true,
'show_ui' => true,
'show_in_rest' => true,
'show_admin_column' => true,
'query_var' => true,
'labels' => [
'name' => 'Types',
'singular_name' => 'Type',
],
]);
register_taxonomy('resource_categories', 'resource', [
'hierarchical' => false,
'show_ui' => true,
'show_in_rest' => true,
'show_admin_column' => true,
'query_var' => true,
'labels' => [
'name' => 'Categories',
'singular_name' => 'Category',
],
]);
register_taxonomy('resource_products', 'resource', [
'hierarchical' => false,
'show_ui' => true,
'show_in_rest' => true,
'show_admin_column' => true,
'query_var' => true,
'labels' => [
'name' => 'Products',
'singular_name' => 'Product',
],
]);
});

Change form name with FormBuilder symfony

I have a question, i know that i can use FromFactoryInterface to set Form name, but how i can do that with FormBuilder ? This get name of class and generate auto name from them, how i can change it to my specify name?
Form Type:
<?php
class ProfileAddPracownikType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('username', null, [
'label_attr' => array('class' => 'bmd-label-floating'),
'label' => 'Nazwa użytkownika',
'mapped' => false,
'attr' => ['class' => 'form-control']])
->add('imie', null, [
'label_attr' => array('class' => 'bmd-label-floating'),
'label' => 'Imię',
'mapped' => false,
'data' => $options['imie'],
'attr' => ['class' => 'form-control']])
->add('nazwisko', null, [
'label_attr' => array('class' => 'bmd-label-floating'),
'label' => 'Nazwisko',
'mapped' => false,
'data' => $options['nazwisko'],
'attr' => ['class' => 'form-control']])
->add('telefon', null, [
'label_attr' => array('class' => 'bmd-label-floating'),
'label' => 'Numer telefonu',
'mapped' => false,
'data' => $options['telefon'],
'attr' => ['class' => 'form-control']])
->add('email', null, [
'label_attr' => array('class' => 'bmd-label-floating'),
'label' => 'Adres e-mail',
'mapped' => false,
'data' => $options['email'],
'attr' => ['class' => 'form-control']])
->add('password', RepeatedType::class, array(
'type' => PasswordType::class,
'invalid_message' => 'Hasła muszą być takie same.',
'options' => array('attr' => array('class' => 'password-field')),
'required' => false,
'first_options' => array('label' => 'Hasło (jeżeli pozostawisz to pola puste hasło nie zmieni się)','attr' => ['class' => 'form-control'],'label_attr' => ['class' => 'bmd-label-floating']),
'second_options' => array('label' => 'Powtórz hasło','attr' => ['class' => 'form-control'],'label_attr' => ['class' => 'bmd-label-floating']),
'mapped' => false,
))
->add('avatar', FileType::class, [
'label_attr' => array('class' => 'bmd-label-floating'),
'label' => 'Wgraj lub aktualizuj avatar (jeżeli nie wgrasz pliku pozostanie standardowy obrazek)',
'mapped' => false,
'required' => false,
'data' => $options['avatar'],
'attr' => ['class' => 'form-control']])
->add('save', SubmitType::class, [
'label' => 'Zapisz profil',
'attr' => ['class' => 'btn btn-primary pull-right']])
;
}
}
Form building inside controller:
$form_profile = $this->createForm(ProfileAddPracownikType::class, $request, array());

symfony2 collection select entity

have this ..
$builder->add('city', 'entity', array(
'class' => '..\Entity\City',
'translation_domain' => $this->translation_domain,
'required' => true,
'expanded' => true,
'invalid_message' => 'form.error.city',
'empty_value' => 'form.placeholder.city',
'query_builder' => function (...\Repository\CityRepository $repository) {
return $repository->get(array(
'enabled' => true,
'locale' => $this->container->get('poisk_raboty.helper.main')->getLocale(),
), true);
},
'attr' => array(
'data-search' => 2,
'data-placeholder' => $this->container->get('translator')->trans('form.placeholder.city', array(), $this->translation_domain),
),
))
;
How can I get cities in form builder, where one element must be like city?
->add('cities', 'collection', array(
'allow_add' => true,
'by_reference' => false,
'required' => true,
'type' => 'entity',
'options' => [
'class' => 'PoiskRaboty\MainBundle\Entity\City',
'translation_domain' => $this->translation_domain,
'invalid_message' => 'form.error.city',
'property' => 'title',
'expanded' => true,
'empty_value' => 'form.placeholder.city',
'query_builder' => function (\PoiskRaboty\MainBundle\Repository\CityRepository $repository) {
return $repository->get(array(
'enabled' => true,
'locale' => $this->container->get('poisk_raboty.helper.main')->getLocale(),
), true);
},
'attr' => array(
'data-search' => 2,
'data-placeholder' => $this->container->get('translator')->trans('form.placeholder.city', array(), $this->translation_domain),
),
]
))

recaptcha symfony2 form edit

i have a form for edit a user and in the class User i have
/**
* #Recaptcha\IsTrue
*/
public $recaptcha;
and my FormType :
$builder
->add('email', 'email', array('attr' => array('placeholder' => 'Email'), 'label' => false, 'translation_domain' => 'FOSUserBundle'))
->add('firstname', null, array('attr' => array('placeholder' => 'Nom'), 'label' => false, 'translation_domain' => 'FOSUserBundle'))
->add('lastname', null, array('attr' => array('placeholder' => 'Prénom'), 'label' => false, 'translation_domain' => 'FOSUserBundle'))
->add('telephone', 'number', array('attr' => array('placeholder' => 'Téléphone'), 'label' => false, 'translation_domain' => 'FOSUserBundle', 'constraints' => array(
new NotBlank(),
new Length(array('min' => 8, 'max' => 8)),
), ))
->add('roles', 'choice', array(
'choices' => array('m' => 'Moniteur', 's' => 'Secrétaire'),
'label' => false,
'multiple' => false,
'expanded' => true,
'mapped' => false
))
->add('adress', 'textarea', array('attr' => array('placeholder' => 'Adresse'), 'label' => false, 'translation_domain' => 'FOSUserBundle'))
->add('cin', null, array('attr' => array('placeholder' => 'CIN'), 'label' => false, 'translation_domain' => 'FOSUserBundle', 'constraints' => array(
new NotBlank(),
new Length(array('min' => 8, 'max' => 8)),
), ))
->remove('recaptcha', 'ewz_recaptcha')
;
}
i removed it but the error message still how to desactivate it ?
the error message returned when i add a new user : This value is not a valid captcha.

Resources