Webform alter with ajax submit callback – field values are empty in callback

At this point I’m doubting if I’m doing it the right way, but I’m struggling with an issue:

I’m adding an Ajax callback to the form alter of a specific form:

function mymodulename_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'webform_submission_matching_node_218_add_form') {
    $form('actions')('submit')('#ajax') = array(
        'callback' => 'matching_api_call',
        //'event' => 'click',
        'effect' => 'fade',
        'speed' => 500,
        'wrapper' => 'block-matchingblock',
        'progress' => (
            'type' => 'throbber',
            'message' => t('Matching...'),
        ));
    }
}

The callback works fine but when I call $form_state->getValues(), I get an array with all my fields but they are simply empty or 0.

My callback function:

function matching_api_call(&$form, DrupalCoreFormFormStateInterface $form_state) {
    // ajax debug
    $response = new AjaxResponse();
    $selector = '#block-matchingblock';
    $content = print_r($form_state->getValues(), true);
    $settings = ();
    
    $response->addCommand(new HtmlCommand($selector, $content, $settings));
    return $response;
}

My output:

Array(
    (field1) =>
    (field2) =>
    (field3) => 0
    (field4) => 0
    (submit) => Match
    (form_build_id) => {formbuildid}
    (form_token) => {formtoken}
    (form_id) => {form_id}
    (op) => Match
)

The entry is added in the backend so it does get submitted. Should I do something else because I’m using Ajax here?

Thanks in advance.

c# – Struct Serialization using Unsafe Field

I want to use structs as a container for data packets for asynchronous networking in C#. Found out that you can create a union style struct without the need to mark the struct itself as unsafe–instead marking the field as unsafe.

Example:

(StructLayout(LayoutKind.Explicit, CharSet = CharSet.Ansi, Size = 8, Pack = 4))
struct DataPacketStruct {
    (FieldOffset(0)) private unsafe fixed byte bytes(8);
    (FieldOffset(0)) private byte header;
    (FieldOffset(4)) private int size;
    
    public void Serialize(ref byte() buffer, int startIndex) {
        unsafe {
            for (int i = 0; i < 8; i++) buffer(startIndex + i) = bytes(i);
        }
    }

    public void Deserialize(byte() buffer) {
        unsafe {
            for (int i = 0; i < 8; i++) bytes(i) = buffer(i);
        }
    }
    
    public int SizeOf() { unsafe { return sizeof(DataPacketStruct); } }
}

I know I need array out of bounds checking–but apart from that. Potential downsides or undefined behaviors? Or is this usage valid?

sharepoint server – WorkflowName field is null under task list

I have created a list workflow from SPD and assigned a task to the approvers group. The workflow is triggering fine but when i want to fetch some of the columns like WorkflowName is coming with blank.
I also verified the Json response from REST API to check values are coming or not? But i found some of the properties are null.

Please some one help me how to fetch these details.

the below is my Json response from the WOrkflow Task list.

API: /_api/web/lists/getbytitle(‘Workflow Tasks’)/items

{
    "d": {
        "results": (
            {
                "__metadata": {
                    "id": "f63099fa-d207-4392-ad0d-384b11f4e967",
                    "uri": "http://inhydvmrstpr02:8080/Iow/_api/Web/Lists(guid'eba6894b-9f6c-4435-86fe-de728ac5a9a3')/Items(46)",
                    "etag": ""2"",
                    "type": "SP.Data.WorkflowTasksItem"
                },
                "FirstUniqueAncestorSecurableObject": {
                    "__deferred": {
                        "uri": "http://inhydvmrstpr02:8080/Iow/_api/Web/Lists(guid'eba6894b-9f6c-4435-86fe-de728ac5a9a3')/Items(46)/FirstUniqueAncestorSecurableObject"
                    }
                },
                "RoleAssignments": {
                    "__deferred": {
                        "uri": "http://inhydvmrstpr02:8080/Iow/_api/Web/Lists(guid'eba6894b-9f6c-4435-86fe-de728ac5a9a3')/Items(46)/RoleAssignments"
                    }
                },
                "AttachmentFiles": {
                    "__deferred": {
                        "uri": "http://inhydvmrstpr02:8080/Iow/_api/Web/Lists(guid'eba6894b-9f6c-4435-86fe-de728ac5a9a3')/Items(46)/AttachmentFiles"
                    }
                },
                "ContentType": {
                    "__deferred": {
                        "uri": "http://inhydvmrstpr02:8080/Iow/_api/Web/Lists(guid'eba6894b-9f6c-4435-86fe-de728ac5a9a3')/Items(46)/ContentType"
                    }
                },
                "GetDlpPolicyTip": {
                    "__deferred": {
                        "uri": "http://inhydvmrstpr02:8080/Iow/_api/Web/Lists(guid'eba6894b-9f6c-4435-86fe-de728ac5a9a3')/Items(46)/GetDlpPolicyTip"
                    }
                },
                "FieldValuesAsHtml": {
                    "__deferred": {
                        "uri": "http://inhydvmrstpr02:8080/Iow/_api/Web/Lists(guid'eba6894b-9f6c-4435-86fe-de728ac5a9a3')/Items(46)/FieldValuesAsHtml"
                    }
                },
                "FieldValuesAsText": {
                    "__deferred": {
                        "uri": "http://inhydvmrstpr02:8080/Iow/_api/Web/Lists(guid'eba6894b-9f6c-4435-86fe-de728ac5a9a3')/Items(46)/FieldValuesAsText"
                    }
                },
                "FieldValuesForEdit": {
                    "__deferred": {
                        "uri": "http://inhydvmrstpr02:8080/Iow/_api/Web/Lists(guid'eba6894b-9f6c-4435-86fe-de728ac5a9a3')/Items(46)/FieldValuesForEdit"
                    }
                },
                "File": {
                    "__deferred": {
                        "uri": "http://inhydvmrstpr02:8080/Iow/_api/Web/Lists(guid'eba6894b-9f6c-4435-86fe-de728ac5a9a3')/Items(46)/File"
                    }
                },
                "Folder": {
                    "__deferred": {
                        "uri": "http://inhydvmrstpr02:8080/Iow/_api/Web/Lists(guid'eba6894b-9f6c-4435-86fe-de728ac5a9a3')/Items(46)/Folder"
                    }
                },
                "ParentList": {
                    "__deferred": {
                        "uri": "http://inhydvmrstpr02:8080/Iow/_api/Web/Lists(guid'eba6894b-9f6c-4435-86fe-de728ac5a9a3')/Items(46)/ParentList"
                    }
                },
                "FileSystemObjectType": 0,
                "Id": 46,
                "ContentTypeId": "0x0108003365C4474CAE8C42BCE396314E88E51F004B3581A3A187724E91023106EE3BD022",
                "Title": "Test task from R47",
                "PredecessorsId": {
                    "__metadata": {
                        "type": "Collection(Edm.Int32)"
                    },
                    "results": ()
                },
                "Priority": "(2) Normal",
                "Status": "Not Started",
                "PercentComplete": null,
                "AssignedToId": 2,
                "TaskGroupId": null,
                "Body": "sfvhvsdf",
                "StartDate": "2020-10-30T09:32:23Z",
                "DueDate": "2020-10-30T01:00:00Z",
                "RelatedItems": "({"ItemId":23,"WebId":"0d2584b8-e9b0-4fb5-8590-b39d5cd52e34","ListId":"8cbcc7fc-f045-4e88-88ac-a9dc0ac29085"})",
                "WorkflowLink": null,
                "OffsiteParticipant": null,
                "OffsiteParticipantReason": null,
                "WorkflowOutcome": null,
                "WorkflowName": null,
                "GUID": "9d48ca07-93f9-44a3-a277-74b0b9720744",
                "TaskOutcome": null,
                "ID": 46,
                "Modified": "2020-10-30T09:32:24Z",
                "Created": "2020-10-30T09:32:23Z",
                "AuthorId": 2,
                "EditorId": 2,
                "OData__UIVersionString": "2.0",
                "Attachments": false
            },
        

7 – How can I conditionally override the field description?

Hello I am using the Reference Field Option Limit module in Drupal 7 and I want to change the explanation text that says:

No options are available for the current form values..

I want to put instead:

Please select a value below.

I tried hook_form_alter but the new phrase is appearing even when there is an option selected in the matching field, which is not what I want. So any idea which hook function should I use?

PS: I don’t want to change that from the module core.

7 – reference field option limit “changing the explanation”

Hello I am using the reference field option limit module in D7 and I want to change the explanation text that says : No options are available for the current form values ..and I want to put instead: please select a value below. I tried hook form alter but the new phrase is appearing even when there is an option selected in the matching field, which is not what I want. So any idea which hook function should I use?
Ps: I don’t want to change that from the module core.

8 – How can I create a custom field type for a select with multiple values?

I need a field type with 3 select in it. The field type is created and works like a charm but I’d like one of these select may have multiple values. What must I change? I add ‘#multiple’ => TRUE, in the widget. But I can’t save my values. I should probably change the type of field in the FieldType but how? Thanks in advance.

wp query – PHP SUM using post Custom Field

I am trying to update a numeric custom field by ‘adding’ a number from a front-end form.
The script I wrote is not adding the existing number, but just updating to the new number entered in the form.

I haven’t been able to make it work but I think there needs to be some sort of conversion for the get_post_meta function for the script to understand it as a number.

The basic script I wrote is:

if(isset($_POST('Add_Work_Task')) == '1'){
    
    $Work_Required_Hours=$_POST('Work_Required_Hours');
    $Parent_Work=$_POST('Work_Parent_TaskGroup');
    $Current_Buried_Hours =get_post_meta( $Parent_Work, 'Work_Buried_Hours',true);

    $Total_Buried_Hours= $Current_Buried_Hours + $Work_Required_Hours;

    $Buried_Required_Hours= array('Work_Buried_Hours' => $Total_Buried_Hours);
            wp_update_post(array(
                                        'ID'        => $Parent_Work,
                                        'meta_input'=> $Buried_Required_Hours,
                                ));
    
}

I also tried

$Total_Buried_Hours= (float)$Current_Buried_Hours + (float)$Work_Required_Hours;

$Total_Buried_Hours= floatval($Current_Buried_Hours) + floatval($Work_Required_Hours);

$Total_Buried_Hours= $Current_Buried_Hours += $Work_Required_Hours;

$Total_Buried_Hours= print_r($Current_Buried_Hours) + $Work_Required_Hours; this one adds 1 only.

and

$Current_Buried_Hours =implode(".",get_post_meta( $Parent_Work, 'Work_Buried_Hours',true));

To narrow it down I know for a fact the problem is with the get_post_meta function, I have tested adding the $_POST twice and it worked like the following:

$Total_Buried_Hours= $Work_Required_Hours + $Work_Required_Hours;

8 – How can I add a new field from config inside hook_update_N?

I have to add taxonomy by php code. Taxonomy has to got 2 fields. I added new function to test_taxonomy.install, and it seems to work:

function taxonomy_update_8805() {

    $config_path = 'modules/feature/test_taxonomy/config/update/';
    $source = new FileStorage($config_path);

    Drupal::entityManager()->getStorage('taxonomy_vocabulary')
        ->create($source->read('taxonomy.vocabulary.regulation'))
        ->save();
}

Added new vocabulary to taxonomy.

Content of file:

langcode: pl
status: true
dependencies:
  module:
    - test_remote_vocabulary
third_party_settings:
  test_remote_vocabulary:
    is_remote: 0
name: 'Test'
vid: regulation
description: 'Test desc'
hierarchy: 0
weight: 0
 

The problematic part is when i try to add fields to the vocabulary.
I created 2 files

field.storage.taxonomy_term.field_regulation_test.yml

langcode: pl
status: true
dependencies:
  module:
    - taxonomy
    - text
id: taxonomy_term.regulation.test
field_name: test_field
entity_type: taxonomy_term
type: text_long
settings: {  }
module: text
locked: false
cardinality: 1
translatable: true
indexes: {  }
persist_with_no_fields: false
custom_storage: false

field.field.taxonomy_term.field_regulation_test.yml

langcode: pl
status: true
dependencies:
  config:
    - field.storage.taxonomy_term.field_regulation_test
    - taxonomy.vocabulary.regulation
id: taxonomy_term.regulation.test
field_name: test_content
entity_type: taxonomy_term
bundle: regulation
label: TEST
description: 'Tekst test'
required: true
translatable: false
default_value: {  }
default_value_callback: ''
settings: {  }
field_type: text_long

But i am not sure how can i load them in update_xxx function.