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),
),
]
))
Related
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?
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',
],
]);
});
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());
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.
What's the path to display all nodes belonging to a vocabulary ?
In other words, I want to display all terms at once. (I don't want to filter by term, just show all nodes tagged with any term of a vocabulary
You can do this pretty easily by grabbing a copy of views and using an appropriate filter. Heck, you can do it where the vid is part of the path, so it works for all of the vocabularies. Hold on...
Yeah, I thought so. Here's a view I made recently that does this - just copy/paste this into the view import.
$view = new view;
$view->name = 'vocabulary';
$view->description = 'Displays all nodes in a vocabulary';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('sorts', array(
'sticky' => array(
'order' => 'DESC',
'id' => 'sticky',
'table' => 'node',
'field' => 'sticky',
'relationship' => 'none',
),
'created' => array(
'order' => 'DESC',
'granularity' => 'second',
'id' => 'created',
'table' => 'node',
'field' => 'created',
'relationship' => 'none',
),
));
$handler->override_option('arguments', array(
'vid' => array(
'default_action' => 'not found',
'style_plugin' => 'default_summary',
'style_options' => array(),
'wildcard' => 'all',
'wildcard_substitution' => 'All',
'title' => '%1',
'breadcrumb' => '',
'default_argument_type' => 'fixed',
'default_argument' => '',
'validate_type' => 'none',
'validate_fail' => 'not found',
'id' => 'vid',
'table' => 'vocabulary',
'field' => 'vid',
'validate_user_argument_type' => 'uid',
'validate_user_roles' => array(
'2' => 0,
'3' => 0,
'4' => 0,
'5' => 0,
),
'relationship' => 'none',
'default_options_div_prefix' => '',
'default_argument_fixed' => '',
'default_argument_user' => 0,
'default_argument_php' => '',
'validate_argument_node_type' => array(
'blog' => 0,
'poll' => 0,
'faq' => 0,
'forum' => 0,
'event' => 0,
'link' => 0,
'page' => 0,
'story' => 0,
),
'validate_argument_node_access' => 0,
'validate_argument_nid_type' => 'nid',
'validate_argument_vocabulary' => array(
'1' => 0,
'5' => 0,
'3' => 0,
'6' => 0,
'4' => 0,
'7' => 0,
'8' => 0,
'9' => 0,
'10' => 0,
'11' => 0,
'12' => 0,
),
'validate_argument_type' => 'tid',
'validate_argument_transform' => 0,
'validate_user_restrict_roles' => 0,
'validate_argument_node_flag_name' => '*relationship*',
'validate_argument_node_flag_test' => 'flaggable',
'validate_argument_node_flag_id_type' => 'id',
'validate_argument_user_flag_name' => '*relationship*',
'validate_argument_user_flag_test' => 'flaggable',
'validate_argument_user_flag_id_type' => 'id',
'validate_argument_php' => '',
),
));
$handler->override_option('filters', array(
'status' => array(
'operator' => '=',
'value' => '1',
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'status',
'table' => 'node',
'field' => 'status',
'relationship' => 'none',
),
));
$handler->override_option('access', array(
'type' => 'none',
));
$handler->override_option('cache', array(
'type' => 'none',
));
$handler->override_option('use_pager', '1');
$handler->override_option('row_plugin', 'node');
$handler->override_option('row_options', array(
'relationship' => 'none',
'build_mode' => 'teaser',
'links' => 1,
'comments' => 1,
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'vocabulary/%');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
'name' => 'navigation',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
'name' => 'navigation',
));