## 8 – Newly created field not being added to entity

I have created a form that adds a subset of field types to an entity (does not support bundles). (the reason for the custom form is that end users find the Drupal standard ‘Manage fields’ workflow too difficult) The class extends FormBase. When the ‘submitForm’ function is executed, the field is saved but not added to the entity.

This is the code to save a date field (with text values filled in for explanation purposes):

``````\$field_storage_values = (
'field_name' => 'field_test_date',
'entity_type' => 'my_entity_id',
'type' => 'datetime',
'translatable' => TRUE,
);

\$field_values = (
'field_name' => 'field_test_date',
'entity_type' => 'my_entity_id',
'bundle' => 'my_entity_id',
'label' => 'Test Date',
'translatable' => FALSE,
);

\$this->entityTypeManager->getStorage('field_storage_config')->create(\$field_storage_values)->save();
\$field = \$this->entityTypeManager->getStorage('field_config')->create(\$field_values);
\$field->save();
``````

When the form is submitted, the field is created correctly but not added to the entity.

When I export the field configuration to YML, the following appears under dependencies:

``````dependencies:
config:
- field.storage.my_entity_id.field_test_date
``````

Creating an identical Node field results in the following field configuration YML dependencies:

``````dependencies:
config:
- field.storage.node.field_test_date
- node.type.basic_page
``````

I suspect the field created with my custom form should also add the second configuration dependency like:

``````my_entity_id.type.my_entity_id
``````

I tried adding the following before the field is saved but the ‘addDependency’ function is protected.

``````\$field->addDependency('config', 'my_entity_id.type.my_entity_id');
``````

## p adic – Universal field extension in which \$nu(a) = 1\$ for each valuation \$nu\$

Let $$K$$ be a field, and let $$a in K$$ be an element.

I seek the universal ring $$A$$ with a map $$K rightarrow A$$, where each valuation $$nu : A rightarrow Lambda cup { infty }$$, with $$Lambda = (Lambda, +, 0)$$ a totally ordered abelian group sends $$a$$ to $$0$$.

This is analogous to localization, except with valuations instead of prime ideals.

## validation – When should the valid visual cue be shown to the user on a pre-filled form field?

It makes sense to show a valid visual cue (eg: green border, green check, etc) when a user is filling a form field and the data is considered valid.

What if the user opened the form with pre-filled data? For example, when editing something.

When would be the appropriate moment to show the valid visual cue on form fields that were not edited by the user?

On focus and blur events?

When the form is submitted?

Never?

## add custom field + custom post

this is the first time that I am doing a complex project (at least for me). I created a custom post and custom fields in the home. Unfortunately I can’t see the custom field inserted inside a group instead of “This bottle was produced in 2014” Unfortunately I see the field before the verification but not as a result of the echo. Can anyone help me?

`````` <?php

\$args = array(
'post_type' => array('wine_code', 'page'),
'order' => 'ASC',
'posts_per_page' => -1,
);

// Eseguo la query
\$the_query = new WP_Query(\$args);

// Conto gli elementi
\$count = \$the_query->post_count;

\$output= (isset(\$_POST('submit')))?\$_POST('input'):'';

?>

<?php
\$categories = get_categories(); \$count = count(\$categories);
foreach (\$categories as \$category) {}
?>

<p data-aos="fade" style="color:#fff;">Inserisci il codice riportato sulla bottiglia<p>

<form method="post" style="width: 50%;margin: auto;" data-aos="fade">
<input type="text" class="form-control" name="input"/> <!-- thiss is where the user enters text -->
<input type="submit" class="btn btn-primary" name="submit" value="trova">
</form>
</section>
<!-- Type service-->
<section class="webpage__type-service type-service">
<?php
\$first_query = new WP_Query( \$args );
while (\$first_query->have_posts()) : \$first_query->the_post();
//the_title();       //echo the title
//the_content();    //echo the content

\$post_id = get_the_ID(); // or use the post id if you already have it
\$category_object = get_the_category(\$post_id);
\$category_name = \$category_object(0)->name;

\$str = get_the_content();
\$choices = explode("-",\$str);
//var_dump(\$ctg);

//echo '<p>' . \$category_name . '</p>';

//foreach(\$choices as \$key => \$value){
//echo '<p>' . \$value  . '</p>';}

if (in_array(\$output, \$choices)) {

if (\$category_name == "2014") {
echo "This bottle was produced in 2014";

} elseif (\$category_name == "2015") {
echo "Questa bottiglia è stata prodotta nel 2015";
}
}
endwhile;

wp_reset_query();
?>
``````

Thanks!!

## 8 – Views field override and use it in Global: Custom Text

In Drupal8, I have created a view of content and add a relationship of the user account field which is referenced entity of the content.
So, Basically I have one content type and in the account fields I have added one content referenced field, there user can select multiple values.

Now in the view I am showing the content and using the Global custom field I am overriding the output of the view.

In the field of referenced entity under view I am getting multiple values like 1,2,3,4,5 and I want something like if node id is present inside this multiple values then I want to display some text.

Can anybody let me know how can I achieve this?

I have tried something like below under Global: custom text field but it did not worked.

``````{% if nid in field_ref_content %}
<p>Lorem Ipsum</p>
{% endif %}
``````

I have tried to override the twig as well for that field and able to achieve the things what I want to show like some custom text, but that only rendered when we are using that field in view.

when I used that field’s replacement pattern inside that Global: custom text, that is returning only the default value which is 1,2,3,4,5 not the one which I have override using the view field override hook

``````Hook_preprocess_views_view_field
``````

Can someone please guide me, I spend so much time for this but no luck.

## 8 – Overwrite field description in an image widget

I have an image field (multiple).

In the node form, the ImageWiget has a `process` method that adds previews and form fields for images that have already been uploaded.

The description for the title tag is hard-coded on line 278: `'#description' => t('The title is used as a tool tip when the user hovers the mouse over the image.')`. We are actually showing the title as a caption and not a tooltip.

How can I override the description?

## 8 – Pathauto pattern for a content type depending on a reference field?

Description: There is a content-type, which has field, referencing taxonomy term. The term is in “Content class” dictionary. This term is used in views to filter the right content for the view. When a link in the view is clicked, it opens the node. This is OK.
So, it is needed pathauto to generate /Content class term/Content_title_name when this node is opened.

What did not work: `(node:field_content_class:value)/(node:title)`. This is not accepted, produces error: `Path pattern is using the following invalid tokens: (node:field_`

The accepted (by Drupal) pattern: `(node:field_content_class)/(node:title)` generates alias, containing only the (node:title) part. The first component is empty.

This is made to not create separate content-types for nodes with the same fields.

## sharepoint online – Accept date and time field on queries

I created a date/hour field and the documents only appear on the page when the date is <=Today.
I set this on the query RefinableDate13 <={{undefined | amUtc | amDateFormat:’YYYY-MM-DDTHH:mm:ss’}} and works fine in webpart queries. But it seems that didn’t work in the notification hub.

On the query of Notification Hub only work if I put RefinableDate13 <={Today}. But this isn’t a solution, because it does not consider the hours. {Today} is set like 2021-04-15T00:00:00 and my refinableDate13 has an hour.

How can I do to accept that on the query of the notification hub?

Best regards.

## interaction design – How do I let users know the field can be edited without putting it in text?

I am designing something like a wallet where users can withdraw from it. I’d like to give users the option to withdraw any amount, however, I do not know how to let my users know in a really obvious way that the amount can be edited. Currently, I’m deciding to put a text saying ‘click here for desired amount’ and connecting it via an arrow to the bottom \$300.70 for users to know.

If you do not understand where I am coming from, do leave a comment as well! Thank you :]

## 9 – Fetch Book field values on child level only once

I’m working on a project where I use the core Book functionality to create my sites structure. I have three content types:

1. `Reader`
2. `Issue`
3. `Article`

Where `Issue` is a child of `Reader`, and `Article` is a child of `Issue`.

For this project I creates multiple custom modules to:

• Set books access permissions
• Change the books frontpage
• Set the books theme
• Add custom css settings per book

For all these modules I create a field in the `Reader` content type. But I want all its child nodes to also be affected by these field settings.

Now to do this I use the following code (example is taken from my custom css module):

``````if (\$node->bundle() == 'reader') {
\$book = \$node;
} else if (\$node->bundle() == 'edition' || \$node->bundle() == 'article') {
//if edition or article
//get parent book
But since I’m doing this in all my module I thought…this is not good for performance because I’m using `Node::load` multiple times for the same thing. So I want to improve this method, if necessary.