How can I programmatically add the shipping address to the payment form?

I am making a custom shipping module. When a user selects the shipping method, I want them to fill in the shipping address fields with some custom address data.

I have overridden the selected shipping method handler as follows:

var config = {
    map: {
        '*': {

I want to programmatically set the values ​​of the form field on the checkout page. Something like:

), function (quote, shipping) {
    'use strict';

    return function (shippingMethod) {
        shipping.street("99 Road Street");"New York");

Is there a way to do this without simply dumping the values ​​using jquery?

8 – How can I programmatically delete a custom menu?

I am writing a hook_deploy_N which moves a bunch of menu items from an outdated custom menu to some newer ones. So far so good. After moving the items, I want to delete the previous menu, but I can't understand how. DrupalCoreMenuMenuTreeStorage have a delete function that may be what I'm looking for but the DrupalCoreMenuMenuTreeStorage the object is housed inside the DrupalCoreMenuMenuLinkTree, which I can at least load, but it has protected status, and I don't see a way to get to it. Also, I'm not 100% convinced that is what I want in any way.

unit: create a trigger programmatically inside an abnormally shaped room

So I am trying to create a trigger in each of my rooms. These rooms can be created by players. Basically, I need to know all the objects in a room. These rooms can be molded in strange and wonderful ways. Am I struggling to figure out how to "fill" an area? The other problem is that some walls are curved.

My current thinking is:

  • Go through all the walls in one scene. Make 4 beam transmissions on each side of the wall and see if we collide with other walls. If we do, we are probably in a room.

  • From scrolling, literally check each adjacent node until we fill the room. However, once I have this, I am not sure what to do with it.

How do I create limits to verify collisions with this data?

magento2: what is the correct way to empty the cache using TAG programmatically? (including varnish)

I have been looking for a correct way to flush the cache using tags programmatically and have found 2 different solutions when it comes to CMS pages:

  • Using CacheInterface as described here, it actually proposes something as easy as the following code. Properly clear the page cache at the Magento cache level, but it doesn't clean the cache on the varnish side:
  • A second approach using Magento PageCache Model Cache Type, which seems to be specific to the cms page (although I'm not 100% sure). It proposes something like the code below. Clear the Magento and Varnish cache. But it seems to empty the cache for ALL pages, even though we passed a specific tag array.
    $this->pageCache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, (cache_TAGS_array));
  • Note: the label array is of type (cms_p_2)

My question then is:

  • How can I empty the cache of the home page (only the home page) for Magento and Varnish? None of the above solutions provides a 100% good result.

views – Create a custom block programmatically in Drupal 8

I couldn't find a way to show view and restrict certain roles.

But I have managed to solve the problem in another way.

I created a script in Admin> Structure> Block> My_Block> Configure> PHP Visibility:

$hide_from_roles = array('administrator', 'sefii', 'membership');
 if (count(array_intersect($heh, $hide_from_roles)) > 0) {
    $match = FALSE;
return $match;

8 – How to programmatically "place" and order in commerce?

When making a payment through the Commerce administration interface; Orders are not completed. I can see a Place Order button when I see a cart order; which seems to do the trick. I need to do this in code.

I know I need to react to the commerce_order.order.paid event, but I'm not sure what to do there.

I found this post: How do I programmatically update the order status? suggesting that I need to "apply a transition". But the suggestion there doesn't work.

I opened a new question for this as I am specifically asking about "placing an order"; whereas that question was about simply changing the status of the Order.

block editor – How can I programmatically open Gutenberg?

I want to edit content in frontend and backend with the Gutenberg editor in a popup.
I pass the content to the editor with JavaScript, I open it, I edit the content in Gutenberg and when I close it I pass the content to a variable again.

Now several questions arise:

  • Loading WordPress with a pageless page or cpt page does not load Nor with the "Gutenberg Ramp" plugin with which Gutenberg should always be loaded.

So the question, is there a possibility to load Gutenberg with the init hook?

If so, how do I proactively start Gutenberg?

Thank you very much for the advice.


category – Error "DDL declarations are not allowed in transactions" when programmatically reindexing using Event Observer Magento 2.3.0

I'm actually trying to reindex the category data while saving the category
from the backend but I get an error DDL statements are not
allowed in transactions
in the log file while programmatically reindexing. Please
check the following code.

Provider Module etc events.xml



Provider Module Observer Categoryreindex.php

_logger = $logger;
        $this->_indexerFactory = $indexerFactory;

    * @param MagentoFrameworkEventObserver $observer
    * @return void
    public function execute(EventObserver $observer) { 

             $this->reIndexing(); // Running Reindexing programmatically 
             $this->_logger->info("Category Save Reindex....");

        } catch(Exception $e) {
            $this->_logger->info("Category Save Reindexing Exception Message....".$e->getMessage());

    * Reindexing Category States programmatically 
    * @param none
    public function reIndexing() {
       $indexerIds = $this->indexerIds;

       foreach ($indexerIds as $indexerId):
            $indexer = $this->_indexerFactory->create();


views – Programmatically add max-age cache

I tried to set the max-age cache to 0 on hook_views_pre_viewin hook_views_pre_build and in hook_views_query_alter But it just doesn't work.


function my_module_views_pre_build(ViewExecutable $view) {
  $view->element('#cache')('max-age') = 0;

The views cache the response until the caches are cleared.

I need to do this programmatically because I need to force the views not to cache the results for more than 10 minutes depending on some conditions.

Edit later: The problem discussed in "How to use max-age" does not apply in my case. I know how to use cache tags, contexts and maximum age for rendered pages / arrays and they work fine. But for the views I can't make them work.

8 – Create configuration storage programmatically for list_string

In a paragraph type, I have a field that I want to migrate to a new field of type "list_string". To do this on deployment and just like our automatic deployment start with a database update followed by importing configurations, I want to programmatically create the new field before migrating to another hook_update.

I am using the example in this article which is perfect except I have a problem because my new field is of type list_string. My setting for is:

langcode: fr
status: true
    - options
    - paragraphs
id: paragraph.field_types_link
field_name: field_types_link
entity_type: paragraph
type: list_string
      value: anchor
      label: Ancre
      value: internal
      label: Interne
      value: external
      label: Externe
  allowed_values_function: ''
module: options
locked: false
cardinality: 1
translatable: true
indexes: {  }
persist_with_no_fields: false
custom_storage: false

When I create my new field based on my config file like so:

$field_storage_link = Drupal::service('')->read('');


I have this error

(error) Configuration property settings.allowed_values.0.label.0 does not exist.

If I remove the list of allowed values, it works and I can add my field to the paragraph packages, but in this case, I can't perform the migration correctly because my field's allowed values ​​are empty and I don't know how to update it programmatically. Can someone explain what is the problem in my code and how to fix it.