8 – Conditional display field based on the comparison with another field

I have an event content type with a start date (field_eventdate) and an optional end date (field_eventend).
Although it is optional, users often fill in the end date with the same date as the start date.
So I want to hide the end date if it matches the start date, or show it on the same line as the start date if it's different.


2020-02-02 10:00
Here comes more text for a single day event


2020-02-02 10:00 - 2020-02-03 16:00
Here is more text for a multiday event

So far, I've been able to delete the end date from the render array if it's the same:

function mytheme_preprocess_node__event(&$variables) {
  $startdate = $variables('content')('field_eventdate')(0)('#markup');
  $enddate = $variables('content')('field_eventend')(0)('#markup');

  if ($startdate === $enddate) {
  else {
    // add an &em-dash; so the dates are nicely spaced
    $variables('content')('field_eventend')(0)('#markup') = " — " . $enddate;
    // add float-left to the start date so they end up on the same line
    // TODO: what goes here?

However, I can't figure out how to tell in a branch template that I have a start and an end date, so I add CSS classes with the "float" addition to line them up.

I tried to use the & # 39; field_eventdate & # 39; add a special attribute and add a class with a left-turning cursor to the branch template for the field, but the custom attribute is lost somewhere.

How can I solve this problem?

8 – Default value for the date / time field definition in the content entity?

You must pass a callback function that will be evaluated when the entity is saved. When you evaluate the time value in YourEntity::baseFieldDefinitionsthe default value is set every time the entity type is installed.

DrupalDateTime::createFromTimestamp cannot be used as a callback because you are expected to pass a timestamp. The default callback must take two arguments: the entity to be saved and the field definition itself:

  • DrupalCoreEntityFieldableEntityInterface $entity
  • DrupalCoreFieldFieldDefinitionInterface $definition

For more information, see the API documents: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Field%21FieldConfigInterface.php/function/FieldConfigInterface%3A%3AsetDefaultValueCallback/8.7.x

So you need to create a callback function, e.g.

use DrupaldatetimePluginFieldFieldTypeDateTimeItem;

// ...

function mymodule_get_current_datetime($entity, $definition) {
  $current_time = DrupalDateTime::createFromTimestamp(time());
  return $current_time->format(DateTimeItem::DATETIME_STORAGE_FORMAT);

And then pass this callback as a string.

$fields('start_date') = BaseFieldDefinition::create('datetime')
  ->setLabel(t('Start date'))
  ->setDescription(t('Start date in GMT time.'))
  ->setDisplayOptions('view', (
    'label' => 'above',
    'type' => 'string',
    'weight' => -4,
  ->setDisplayOptions('form', (
    'type' => 'datetime_default',
    'weight' => -3,
    'default_value' => DrupalDateTime::createFromTimestamp(time()),
  ->setDisplayConfigurable('form', TRUE)
  ->setDisplayConfigurable('view', TRUE);

Unit – recoil to zone on non-rectangular field

I have a playing field that is divided into 4 zones (see picture below)


The player (blue) is in the second zone, while 2 enemies (red) are in the third zone. If the player throws an object and hits the enemy, the enemy will be knocked back in the next zone (4), but their translation should remain in the zone that corresponds to the direction of the hit.

Question: How do I find X?

Note that it can be on any form of playing field (triangular, hexagonal, circular, …)

sharepoint online – How to update the existing field value in a new field as soon as the existing field value is changed

Please help me for the following problem.

I have a sharepoint list. In this list I have the following fields.

1- Employee name
2- department
3- Current project name
4- Date of the current project
5- Current project end date
6- Previous project name
7- Date assigned to previous project
8- previous project end date.

Senario: If an employee "A" is assigned to "Project1" from 1-1-2019 to 2-2-2019
As a result, my field is updated with the details above such as "Employee Name, Current Project Name, Assignment Date, and Current Project End Date" Now after the end date "2-2-2019", employee "A" will be assigned to project "B" from 2-3-2019 to 3-3-2019. Therefore, my existing field data is also changed to new data, such as "current project name, project assignment date and end date". However, if this changes, my old entry, which shouldn't be removed, will be removed. It should be updated under "Previous Project" name
, Date assigned to previous project
& Previous project end date. "Field. As it is possible. Please help me with this.

8 – Use a custom field as a subfield in another custom field

Some time ago I successfully implemented a custom field (this was an extension of the DateRange field type to improve the control of the presentation, etc.).

I have a couple of other use cases where I could use a modified Daterange field as a subfield in another custom field type. Now I know that I could implement it the same way in any new custom field type, much easier if I could just insert my custom Daterange field. If this is not possible, is it best to set my custom data type as the base type and extend it for each field type to be created? Or is there another solution (I don't want to use paragraphs because I don't get the level of adjustment I want)

User behavior – "Search" button or input field for the search in the top navigation bar of the website?

In this article by Nick Babich, Design a Perfect Search Box, he suggests that when it matters, the search box should be highlighted and the text box should appear instead of just the button. The main reasons are:

  • This can be the fastest way for users to discover.
  • The search function, which is hidden behind a symbol, makes the search function less noticeable.
  • Search hidden increases the cost of interaction.

sharepoint online – field value update in the next field

I am not sure if there is a solution to the requirement below. Please help if there is one.

I have two fields in the Sharepoint list.

1) Username: (users & groups)
2) Current project: (Dropdown) (Ex-Contoso)
3) Deployment date: 1-1-2019 (date and time)
4) Existing customer name: (The current project name should be adopted automatically if I change the value (From contoso to Microcraft) in the current project status.
5) Availability date available: (As above, if the delivery date value changes, the existing date value should be used as the delivery date value.)

Please help me with this.