database design – MySQL: Should I add NOT NULL UNIQUE to the field for primary key?

Hi I’m completely new to MySQL, I’m creating a database and my question is that:

Should I add NOT NULL UNIQUE to the field for primary key?

For example I have:

    AccountID varchar(25) NOT NULL,
    PRIMARY KEY(AccountID)           // <------- (*)

I’m thinking about whether the (*) would implicitly mark the field as UNIQUE NOT NULL.

Btw, could anyone provide good resources about best practices of MySQL(I’m currently interested about creating table) so I won’t add redundant restriction(s) in any schema.

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,

$field = $this->entityTypeManager->getStorage('field_config')->create($field_values);

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:


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

    - node.type.basic_page

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


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.

How to update a field in a Firestore document only if it exists (using Python)?

I found zero ready-to-use answer on the internet and wrote this Python code snippet for my own use case, and I’m sharing here for others to reuse:

key = 'field'
key_nonexistent = 'field_nonexistent'

doc_ref = db.collection('test_coll').document('test_doc')
doc_ref.set({key: False})
# doc_ref.update({key_nonexistent: True})  # This will create 'field_nonexistent' -- not desired

dict_doc = doc_ref.get().to_dict()

if key in dict_doc.keys():
    doc_ref.update(key: True}  # This will update the field only if it exists -- desired

if key_nonexistent in dict_doc.keys():
    doc_ref.update(key_nonexistent: not dict_doc(key_nonexistent)}  # This proves the field won't be created if not existent. You can uncomment/comment out the commented line above to see yourself

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.

enter image description here

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?

When the form is loaded?

On focus and blur events?

When the form is submitted?


forms – How to add “clone” button to WebformMultiple field

I created a custom composite field with a dozen or so fields, in a custom module extending DrupalwebformElementWebformCompositeBase. I need to add a “clone” button to the webform multiple table operations, which when clicked will create a new instance of the webform widget as the “add” button does, except that it is populated with the values existing in the element that is being cloned.

I asked this question in the webform issue queue and @jrockowitz responded

That is very tricky.

First, you would add the new operation via DrupalwebformElementWebformMultiple::buildElementRow and then your would have to examine the $form_state to parse the values of the previous rows.

One trick to adding new functionality like this is to first disable #ajax and get the functionality working without ajax and then enable #ajax.

I’m relatively new to D8 development, so I don’t understand how to override or otherwise commandeer DrupalwebformElementWebformMultiple::buildElementRow. I know how to make a child class of it and start to add my customizations to it, but I don’t know how to get my class to be the one that is executed in place of WebformMultiple::buildElementRow.

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

This question is already asked here, but the answer selected does not work for Drupal8.

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.

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.

Please share with me your thoughts and opinions. Greatly appreciated!
If you do not understand where I am coming from, do leave a comment as well! Thank you :]

enter image description here

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') {
    //if reader
    $book = $node;
} else if ($node->bundle() == 'edition' || $node->bundle() == 'article') {
    //if edition or article
    //get parent book
    $book = Node::load($node->book('bid'));

//get textcolor from book
$textColor = $book->get('field_textcolor')->getValue()(0)('color');

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.

So is there a way to either:

  • Get the parent books field in a better way inside the modules?
  • Or, create global variables from the parent Book field values, so I have to only fetch them once for every website visit/visitor?

Complex conditional logic for Webform field

I have a complex scenario in Webforms, where field #states depends on multiple OR / AND conditional logic.

For Example:

field_d has a visibility condition where field_a must be filled and either of field_b or field_c must be filled. I am not sure how to proceed with that kind of Yaml logic. I have tried something like below but it seems not to work.


      filled: true


      filled: true


      filled: true