Populate person field of custom list via REST

How do I get the values of get_id() function into person/group field via REST? I know the syntax of the REST part has to be like:

'AssignedToId': {"results": (ID1, ID2,...)}

But how do I load the values into an array and pass this into {"results": ()} ?

var Id = get_id();
'AssignedToId': {"results": (Id)} 

or

'AssignedToId': Id

doesn’t work

EDIT:
Here’s the code

var hostweburl;
 var appweburl;
 var getId = new Array();

// Run your custom code when the DOM is ready.
$(document).ready(function () {


    initializePeoplePicker('peoplePickerDiv');


     //Get the decoded URLs
        hostweburl = GetUrlKeyValue("SPHostUrl");
        appweburl = GetUrlKeyValue("SPAppWebUrl");

        //resources are in URLs in the form:
        //web_url/layouts/15/resource
        var scriptbase = hostweburl + "/_layouts/15/";


        //load the js files and continue to the successHandler
        $.getScript(scriptbase + "SP.Runtime.js",
        function () {
            $.getScript(scriptbase + "SP.js",
                function () { $.getScript(scriptbase + "SP.RequestExecutor.js"); } 
            );
        }
    )

});

// Render and initialize the client-side People Picker.
function initializePeoplePicker(peoplePickerElementId) {

    // Create a schema to store picker properties, and set the properties.
    var schema = {};
    schema('PrincipalAccountType') = 'User,DL,SecGroup,SPGroup';
    schema('SearchPrincipalSource') = 15;
    schema('ResolvePrincipalSource') = 15;
    schema('AllowMultipleValues') = true;
    schema('MaximumEntitySuggestions') = 50;
    schema('Width') = '280px';
    this.SPClientPeoplePicker_InitStandaloneControlWrapper(peoplePickerElementId, null, schema);
}

// Query the picker for user information.
function getUserInfo() {

    // Get the people picker object from the page.
    var peoplePicker = this.SPClientPeoplePicker.SPClientPeoplePickerDict.peoplePickerDiv_TopSpan;

    // Get information about all users.
    var users = peoplePicker.GetAllUserInfo();
    var userInfo = '';
    for (var i = 0; i < users.length; i++) {
        // Get the user's ID by using the login name.
        $.when(getUserId(users(i).Key))
        .then(function (result) {
                console.log(result.get_id());
                getId = result.get_id();
        });

    }

   // Get user keys.
   var keys = peoplePicker.GetAllUserKeys();

}

//Function to prepare and issue the request to get SharePoint Data
    function execCrossDomainRequest() {


       var rest_data = JSON.stringify({
            '__metadata': { 'type': 'SP.Data.TicketsListItem' },
            'Title': $("#Title").val(), 
            'AssignedToId': { 'results': getId}, 
            'Issue_x002d_Status': $("#status").val(), //be sure to enter the INTERNAL column name!
            'Priorit_x00e4_t': $("#prio").val(), //be sure to enter the INTERNAL column name!
            'Kategorie': $("#kat").val() 
        });


        //executor: The RequestExecutor object
        //Initialize the RequestExecutor with the add-in web URL
        var executor = new SP.RequestExecutor(appweburl);


        // Issue the call against the add-in web.
        // To get the title using REST we can hit the endpoint:
        // appweburl/_api/web/lists/getbytitle('listname')/items
        // The response formats the data in the JSON format.
        // The functions successHandler and errorHandler attend the sucess and error events respectively
        executor.executeAsync({
            url: appweburl + "/_api/SP.AppContextSite(@target)/web/lists(guid'F1176C57-5AA4-4E73-9865-0EE5638FA682')/items?@target='" + hostweburl + "'", //use guid of list to make sure there are no errors
            method: "POST",
            body: rest_data,
            headers: {
                "Accept": "application/json; odata=verbose", "content-type": "application/json;odata=verbose", "X-RequestDigest": $("#__REQUESTDIGEST").val(),
            },
            success: successHandler,
            error: errorHandler
        });

    }
    //Function to handle the success event.
    function successHandler() {

    }

    // Function to handle the error event
    function errorHandler() {

    }

// Get the user ID.
function getUserId(loginName) {

    var deferred = $.Deferred();

    var context = new SP.ClientContext.get_current();
    var user = context.get_web().ensureUser(loginName);
    context.load(user);
    context.executeQueryAsync(
         Function.createDelegate(null,
            function () { deferred.resolve(user); }),
        Function.createDelegate(null,
            function (sender, args) { deferred.reject(sender, args); }));

    return deferred.promise();
};

EDIT2:

$.when(getUserId(users(i).Key)).then(function (result) {
                getId.push(result.get_id().toString());
                alert(getId); 
            });

alert(getId);

the alert is showing me the correct Id’s (from time to time in different order, but that shouldn’t be a problem). Nevertheless there’s nothing populated in my AssignedToId column. All the other columns getting filled.

var rest_data = JSON.stringify({
        '__metadata': { 'type': 'SP.Data.TicketsListItem' },
        'Title': $("#Title").val(),
        'AssignedToId': { "results": getId },
        'Issue_x002d_Status': $("#status").val(), //be sure to enter the INTERNAL column name!
        'Priority': $("#prio").val(), //be sure to enter the INTERNAL column name!
        'Category': $("#cat").val()
    });

    alert(rest_data);

the rest_data alert is giving me “…AssignedToId:{results: ()}..”

EDIT3:

So I’m typing in 3 users and the alerts of alert(getId); are
these

the alert of alert(rest_data); is
this

xml – how to add custom container inside product.info.main container in magento 2.3.1

how to add custom container in class=”product-info-main” referenceContainer=”content” and inside catalog.product.view.xml file

catalog.product.view.xml

  <referenceContainer name="content">
        <container name="product.info.parts" htmlTag="div" htmlClass="product-info-parts" before=""/>
    </referenceContainer>

but it’s not working

terms – Disable custom taxonomy by name in function

I need delete some custom taxonomy with function. Users creates new taxonomies, but when user create any disabled taxonomy (for example named “custom_taxonomy1”) so WP remove it with function (so blacklist for specific taxonomy name).

How can I delete with something like this:

If post type "custom_post_type" – do remove taxonomy with name array "custom_taxonomy1", "custom_taxonomy2"...

or with wp_remove_object_term() function

or I find this, but how achieve it:

function wpse_296972_pre_delete_term( $term_id, $taxonomy_name ) {
    if ( $taxonomy_name === 'organization' ) {
        $objects = get_objects_in_term( $term_id, $taxonomy );

        // delete here .
    }
}
add_action( 'pre_delete_term', 'wpse_296972_pre_delete_term' );

Get Best Deals Custom Essential Oil Packaging – Social Media Marketing (SMM)

We manufacture essential oil packaging boxes for wholesale. we manufacture quality packing boxes for shipping all over the UK. Nowadays the market takes only nice boxes of Essential Oil Packaging it’s all about increasing your daily / monthly sales. Custom Boxes World is one of the UK’s leading printing and essential oil boxes suppliers. If you have the design files ready for Printing Box, that will be great.  These bottles are prepared in such a way that they won’t damage your essential oils and even come out. Our essential oil packaging team ensures that the glasses are stored in a safe and orderly manner.

14de0970667311.5bab1d126122f.jpg

csv – In the CSVlog mode, is there some way to make PostgreSQL log a custom string bases on some kind of SQL session variable or similar?

I have instructed PostgreSQL to csvlog its errors/notices. Then my script reads these files and put them back into a database table, then deletes the log file. This part is all working and stable.

My issue is that I never know which script is associated with an error/notice. As I have very much established by now, there is no such built-in option.

However, it strikes me that maybe I can send a custom string/text to the PostgreSQL session so that the csvlog includes this field when it makes its CSV log? If so, I could set this “session variable” to the path for my script client-side, and then have PG log the field without itself knowing which script was responsible for the error/notice?

Is this possible? If so, how?

(I already do logging client-side, but that’s just for the actual SQL queries, for statistics purposes. That log doesn’t include any errors/notices; the ones which are logged with the csvlog. I have no idea how I would detect these client-side, if it’s even possible. Everything is very cryptic and difficult in this environment.)

8 – Custom form calls different form in modal, submit/ajax callback of second form not called

I created 2 forms:

dms_gift_voucher/src/Form/GiftVoucherForm.php

  ...

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    ....
    
    $form('submit') = (
      '#type' => 'submit',
      '#value' => $this->t('Submit'),
      '#attributes' => (
        'class' => (
          'use-ajax',
        ),
      ),
      '#ajax' => (
        'callback' => ($this, 'confirmGiftVoucher'),
        'event' => 'click',
      ),
    );

    // Dialog box dependency
    $form('#attached')('library')() = 'core/drupal.dialog.ajax';

    return $form;
  }

  ...

  /**
   * Callback for opening the modal form.
   */
  public function confirmGiftVoucher(array $form, FormStateInterface $form_state) {
    $response = new AjaxResponse();

    // Get the modal form using the form builder.
    $modal_form = $this->formBuilder->getForm('Drupaldms_gift_voucherFormGiftVoucherConfirmForm', $form_state->getValues());

    // Add an AJAX command to open a modal dialog with the form as the content.
    $dialog_options = (
      'width' => 'calc(100% - 20px)',
      'dialogClass' => 'modal--gift-voucher-confirm',
    );
    $response->addCommand(new OpenModalDialogCommand($this->t('Test'), $modal_form, $dialog_options));

    return $response;
  }

dms_gift_voucher/src/Form/GiftVoucherConfirmForm.php

  ...

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state, $values = ()) {
    ...
    
    $form('submit') = (
      '#type' => 'submit',
      '#value' => $this->t('Confirm'),
      '#weight' => 100,
      '#attributes' => (
        'class' => (
          'use-ajax',
        ),
      ),
      '#ajax' => (
        'callback' => ($this, 'submitModalFormAjax'),
        'event' => 'click',
      ),
    );

    // Library
    $form('#attached')('library')() = 'core/drupal.dialog.ajax';


    return $form;
  }

  ...

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    // Never called!
  }

  /**
   * {@inheritdoc}
   */
  public function submitModalFormAjax(array &$form, FormStateInterface $form_state) {
    $response = new AjaxResponse();
    // Never called!
    return $response;
  }

The first form works correct, the submit is called, the ajax callback renders the modal with the 2nd form.
But when i submit the 2nd form, nothing happens, no submit, no ajax callback called from the 2nd form.

How can i fix this? Any suggestions.

(Every example of drupal modal forms start with a link trigger with routing, but i find it strange why this approach doesn’t work).

Custom javascript runs before block loaded

I have two jQuery calls to modify two divs on a page. One works, the other attempts to work, but the block is lazy loaded, likely using BigPipe. This helpful doc page is what I’m referring because it explicitly says this is the way to run javascript after the DOM has loaded and all elements are available.
I’ve given up incorporating it into my custom module and now have moved it to the theme. This is the mytheme.libraries.yml

global-styling:
  version: 1.x
  css:
    theme:
      css/custom.css: {}
global-scripts:
  version: 1.x
  js-footer:
    footer: true
  js:
    support/mine.js: {}
  dependencies:
    - core/jquery
    - core/drupal
    - core/drupalSettings
    - core/jquery.once

Here is the mine.js

(function ($, Drupal, drupalSettings) {
  let varcolor = {"one": '#694D75', "two": '#AD1A1A', 'white': '#fffff0'};
  var siteId = drupalSettings.sitelib;
  function myheader(context, settings) {
    jQuery(context).find('.msites-bgcolor').once("siteColor").each(function()
  {
    jQuery(this).css('background-color', varcolor(siteId));
  });
  }

function mysidebar(context, settings) {
  var siteId = drupalSettings.sitelib;
  $('#sidebar .title-box', context).once("siteColor").each(function (){
    $(this).css('.background-color', varcolor(siteId));
  });
  }

  Drupal.behaviors.siteColor = {

    attach: function (context, settings) {
    mysidebar(context, settings);
    myheader(context, settings);

  }
}

})(jQuery, Drupal, drupalSettings);

Running in browser console, I see my script being invoked before the sidebar block has even loaded. So when the mysidebar() function is invoked, jQuery cannot find the block because the block hasn’t loaded yet.

This is not a block generated by a custom module, it’s just a block created by the customer in /admin/structure/block

What am I not seeing? How to ensure this runs when the DOM has loaded all the way?

magento2 – How to show customer data ( name, surname, address ) on my custom checkout step after shipping step?

I have created custom checkout step after shopping step.
Now i need to show there customer’s information from shipping step (first name, last name, address, city, country, phone number, etc ) and his orders ( name of order and quantity ).
I don’t know how to do it, please give any advices.

magento2 – How to override product custom option price too in magneto 2

I am overriding the price using observer and it works fine until the product has custom options. I do updated the price for special price/regular price but seems like because of not handling the custom option my product are not being added to the cart. I am sharing what i have done so far:

created an observer:

<?xml version="1.0"?>
 <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
 <event name="checkout_cart_product_add_after">
        <observer name="set_custom_price_after_add_to_cart" instance="vendormoduleObserverCustomPrice" />
 </event>
</config>

and related class:


namespace vendormoduleObserver;

use MagentoFrameworkEventObserverInterface;

/**
 * Class CustomPrice
 * @package vendormoduleObserver
 *
 */
class CustomPrice implements ObserverInterface
{
    
    public function execute(MagentoFrameworkEventObserver $observer) {
        $item = $observer->getEvent()->getData('quote_item');
        $item = ( $item->getParentItem() ? $item->getParentItem() : $item );
        $regularprice = $item->getProduct()->getPrice();
        $price = 2*$regularprice;
        $item->setCustomPrice($price);
        $item->setOriginalCustomPrice($price);
        $item->getProduct()->setIsSuperMode(true);
}
}

Now my problem is how to handle the custom option prices??
Please help!!

Using custom IDP with WP

I got a client and they have a custom made IDP now they are moving to WordPress from Blogger and I made the full setup for the new WP site. Now they want the logins to be made from the IDP and not in the WP site. I tried many plugins but none of them worked. As I have some experience in plugin development I am planning to create a new plugin. But I have some doubts hope someone would help me.

  1. When a user clicks login in WP he should be redirected to the IDP login page with some identifiers. How can I do this? (I guess customizing wp-login will work but I’m unable to find any hook for that)

  2. Then once the user successfully logs-in in the IDP the user is redirected to a Callback URL with some identifiers. How can I create a callback page? Which hooks should I use?

  3. Finally after the user reaches the callback page the script communicates with the server and gets the credentials for logging in. Here how to check if the user is already registered in WP (that is already logged-in at least once) and how to register if not. If yes how to login the user.

Thanks in advance!!!