Getting Too few arguments to function - symfony

hello i have extend and costumize the checkout to an one page checkout, in previous interation i have do the same and it work normally but when i try to do the same in new project sylius 1.10 it show me a probel that i havent found solution this is the one page checkout form:
$builder
->add('address', AddressType::class, [
'data' => $options['order'],
'customer' => $options['customer'],
])
->add('shipping', SelectShippingType::class, [
'data' => $options['order'],
])
->add('payment', SelectPaymentType::class, [
'data' => $options['order'],
])
->add('complete', CompleteType::class, [
'data' => $options['order'],
])
and this is the error that i got:
Too few arguments to function
Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType::__construct(),
0 passed in C:\wamp64\www\project\vendor\symfony\form\FormRegistry.php
on line 89 and at least 1 expected
does the error is in the SelectPaymentType Only?

Related

Drupal 9 How to add pager with entityQuery

We've a Drupal 9 installation and are trying to add a pager using the pagerer module for articles entityQuery, the aim is to list tagged articles in a tag page, but it’s not working. It returns null.
When we dump the data without the pager, using default drupal query, it returns the data of all tagged articles properly.
The code is added in the theme file themeName_preprocess_page hook and being called in page--page.html.twig template file.
Here’s our code:
$query = \Drupal::entityQuery('node')
->condition('status', 1)
->condition('type', 'article');
->pager(2);
$nids = $query->sort('created', 'DESC')
->execute();
if($nids):
$nodesNews = \Drupal\node\Entity\Node::loadMultiple($nids);
$pathNews = base_path();
$pager = [
'articles_data' => $nodesNews,
'results' => [
'#theme' => 'news_pagination',
'#items' => $nodesNews,
'#path' => $pathNews,
'#tag' => $tag
],
'pager' => [
'#type' => 'pager',
'#quantity' => 5
],
];
return $pager;
endif;
And here is the code that calls the query:
<div>
{{ articles_data }}
{{ pager }}
</div>
The above code returns only one page in the navigation and we’ve 10 articles, so given that we set 2 articles per page, the output should be 5 pages instead of 1.
Also articles_data attribute returns null. Could you please help me to find what’s wrong with the code? Happy to share more information as needed, thank you.
Just reading the docs for this module here,
it would seem that you are missing at least the #theme and #style keys in your render array for the pager.
A more likely to succeed version of the above render array would be
$pager = [
'articles_data' => $nodesNews,
'results' => [
'#theme' => 'news_pagination',
'#items' => $nodesNews,
'#path' => $pathNews,
'#tag' => $tag
],
'pager' => [
'#type' => 'pager',
'#theme' => 'pagerer_base',
'#style' => 'standard',
'#config' => [
'display_restriction' => 0,
],
'#quantity' => 5
],
];

Symfony 4 - Difficults with ChoiceType function

I've a Symfony 4 project.
My users can submit holidays.
There are several types of leave (illness, overtime, etc.), and for each of these types, they have a balance.
When they submit a leave, they must choose from the list of leave types the type they wish. But I want to display in this list only those whose balance is greater than 0.
So, in my form I've:
->add('typeConge', EntityType::class, [
'class' => TypeConge::class,
'label' => false,
'placeholder' => "Type d'absence",
'choice_label' => 'nom',
])
And in my User entity, I've the function to take only typeConges with positive balance:
public function getSoldesActif()
{
$soldesTypesConge = $this->soldeConges;
foreach ($soldesTypesConge as $solde) {
if ($solde->getSolde() == 0) {
$soldesTypesConge->removeElement($solde);
}
}
return $soldesTypesConge;
}
But even with the documentation, I don't understand how can I affect this list ?
Can someone help me please ?
You can use the query_builder-option on the entity type to specify which entities are displayed.
It should probably look roughly, something like this:
->add('typeConge', EntityType::class, [
'class' => TypeConge::class,
'label' => false,
'placeholder' => "Type d'absence",
'choice_label' => 'nom',
'query_builder' => function(EntityRepository $repo) {
$builder = $repo->createQueryBuilder('typeConge');
return $builder->where('typeConge.solde > 0');
},
])
The query builder is responsible for which entities are fetched and then displayed in the list. By default it will fetch all entities and with the query_builder-option you can restrict this to your liking using the ORM-query builder from Doctrine.
There is also an example in the docs, you can use as reference: https://symfony.com/doc/current/reference/forms/types/entity.html#ref-form-entity-query-builder

How do I hook up the code to change Drupal module behaviour?

Drupal does not allow me to delete extension (recurring_commerce) as some fields needs to be deleted manually. This issue is described in detalis below.
Solution is to add some code to a file as described in #11 of the issue below.
Basically I need to programmatically delete a field and I have never done it before. Writing kind of a hook (?).
I tried to paste the suggested code before, after the original code as well as replacing the original code with a suggested one.
Every time after changing the code I am restarting the server, running cron and clear cache.
Still I am unable to uninstall the exension from drupal as I have the following message:
The following reason prevents Commerce Recurring from being uninstalled:
The Billing period field type is used in the following fields: commerce_order.billing_period, commerce_order_item.billing_period
Details of the following issue:
please skip to #11
https://www.drupal.org/project/commerce_recurring/issues/2924965
Suggested code to apply:
function commerce_recurring_update_8101(&$sandbox) {
\Drupal::entityManager()->getStorage('field_config')->load('commerce_order.recurring.billing_period')->delete();
\Drupal::entityManager()->getStorage('field_config')->load('commerce_order.recurring.billing_schedule')->delete();
\Drupal::entityManager()->getStorage('field_config')->load('commerce_order.recurring.order_items')->delete();
\Drupal::entityManager()->getStorage('field_config')->load('commerce_order_item.recurring_standalone.billing_period')->delete();
\Drupal::entityManager()->getStorage('field_config')->load('commerce_order_item.recurring_standalone.subscription')->delete();
\Drupal::entityManager()->getStorage('field_config')->load('commerce_order_item.recurring_product_variation.billing_period')->delete();
\Drupal::entityManager()->getStorage('field_config')->load('commerce_order_item.recurring_product_variation.subscription')->delete();
}
function commerce_recurring_update_8102(&$sandbox) {
\Drupal::entityTypeManager()->getStorage('commerce_order_type')->load('recurring')->delete();
\Drupal::entityTypeManager()->getStorage('commerce_order_item_type')->load('recurring_standalone')->delete();
\Drupal::entityTypeManager()->getStorage('commerce_order_item_type')->load('recurring_product_variation')->delete();
}
Original code in my file:
/**
* Add the 'trial_starts' and "trial_ends" fields to subscriptions.
*/
function commerce_recurring_update_8101(&$sandbox) {
$fields = [];
$fields['trial_starts'] = BaseFieldDefinition::create('timestamp')
->setLabel(t('Trial starts'))
->setDescription(t('The time when the subscription trial starts.'))
->setRequired(FALSE)
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'timestamp',
'weight' => 0,
])
->setDisplayOptions('form', [
'type' => 'datetime_timestamp',
'weight' => 0,
])
->setDisplayConfigurable('form', TRUE);
$fields['trial_ends'] = BaseFieldDefinition::create('timestamp')
->setLabel(t('Trial ends'))
->setDescription(t('The time when the subscription trial ends.'))
->setRequired(FALSE)
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'timestamp',
'weight' => 0,
])
->setDisplayOptions('form', [
'type' => 'datetime_timestamp',
'weight' => 0,
])
->setDisplayOptions('form', [
'type' => 'datetime_timestamp',
'weight' => 0,
])
->setDisplayConfigurable('form', TRUE);
$update_manager = \Drupal::entityDefinitionUpdateManager();
foreach ($fields as $name => $storage_definition) {
$update_manager->installFieldStorageDefinition($name, 'commerce_subscription', 'commerce_recurring', $storage_definition);
}
}
/**
* Make the billing_schedule field required on subscriptions.
*/
function commerce_recurring_update_8102() {
$entity_definition_update = \Drupal::entityDefinitionUpdateManager();
$field_definition = $entity_definition_update->getFieldStorageDefinition('billing_schedule', 'commerce_subscription');
$field_definition->setRequired(TRUE);
$entity_definition_update->updateFieldStorageDefinition($field_definition);
}

Symfony 4.2 event POST_SUBMIT is returning null

Im doing 3 forms in Symfony 4.2.5 all with the same code when load states and cities (estados and municipios) but only this form is making me crazy because has the same code that all but doesnt work it always return null in "municipio", and when I print $request it has municipio=1 but in $form->isValid() says that municipio is null and it started when I added FormEvents
Please if someone could help me I'll be grateful, I inspected all my code but this is where its break.
$builder->get('estado')->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
$estado = $event->getForm()->getData();
if (null == $estado) {
$event->getForm()->getParent()->add('municipio', EntityType::class, [
'class' => 'App\Entity\Municipio',
'required' => true,
'placeholder' => '== Selecciona un municipio 1==',
'choices' => []
]);
} else {
$event->getForm()->getParent()->add('municipio', EntityType::class, [
'class' => 'App\Entity\Municipio',
'required' => true,
'placeholder' => '== Selecciona un municipio 2 ==',
'choices' => $estado->getMunicipios()
]);
}
}
);
I had duplicated my field, one in buildForm when add and other in the event and cause bad behaviour.
Symfony dont say that we can not add a field more than 1 time and no error is showing until I needed submit the form and my field was not recognized and always had null value.
I just deleted $builder->add('municipio') and all work fine.

adding Woocommerce attribute to a product via API

Ok, so, I have a fair bit of experience with the Woocommerce API and PHP and use it for lots of product population from XML files. However, I'm having a problem adding attributes. Well, thats not strictly true, the attributes DO add, but then throw up an error after they do.
I'm using the Automattic PHP code and, as I say, it does most things fine.
$data = [
'attributes' => [
[
'id' => 9,
'position' => 0,
'visible' => true,
'variation' => false,
'options' => [
'bathroom'
]
]
]
];
$woocommerce->put('products/123', $data);
but that gives me the error
'Error: Invalid parameter(s): attributes [rest_invalid_param]' in
/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php:348 Stack trace: #0
Although when I look at the product, the attribute has been added correctly.

Resources