This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Drupal\libevents\Plugin\Field\FieldFormatter; | |
use Drupal\Core\Field\FieldItemListInterface; | |
use Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceEntityFormatter; | |
use Drupal\Core\Field\EntityReferenceFieldItemListInterface; | |
/** | |
* Plugin implementation of the 'boolean_taxonomy_term_formatter' formatter. | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_form_alter(). | |
*/ | |
function search_form_views_exposed_form_alter(&$form, FormStateInterface $form_state, $form_id) { | |
$requestStack = \Drupal::service('request_stack'); | |
// Get the current request object. | |
$request = $requestStack->getCurrentRequest(); |
To create a route file with a page callback in Drupal, you can follow these steps:
Create a new file in your module's src/Routing directory, named module_name.routing.yml. In this file, define your route using the YAML syntax. An example of a basic route might look like this:
module_name.example:
path: '/example'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function lib_layouts_entity_view_mode_alter(&$view_mode, EntityInterface $entity, $context) { | |
if ($entity->getEntityTypeId() == 'node' && $entity->bundle() == 'landing_page' && $view_mode == 'full') { | |
if ($entity->hasField('field_layout')) { | |
$field = $entity->get('field_layout'); | |
if (!$field->isEmpty()) { | |
$layout = $entity->get('field_layout')->getString(); | |
$available_modes = \Drupal::service('entity_display.repository')->getViewModes('node'); | |
if (array_key_exists($layout, $available_modes)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$value = NULL; | |
if ( | |
$entity->hasField($field) | |
&& $entity->get($field)->first() | |
&& !empty($entity->get($field)->first()->getValue()) | |
) { | |
$value = array_values($entity->get($field)->first()->getValue())[0]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Get all Node types and all fields | |
$content_types = NodeType::loadMultiple(); | |
foreach ($content_types as $content_type) { | |
$types_options[$content_type->id()] = $content_type->label(); | |
foreach (\Drupal::service('entity_field.manager')->getFieldDefinitions('node', $content_type->id()) as $field_name => $field_definition) { | |
if (!empty($field_definition->getTargetBundle())) { | |
$field_options[$field_definition->getName() . ':' . $field_name] = $field_definition->getLabel(); | |
//display content type names in the drop down |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "drupal/recommended-project", | |
"description": "Project template for Drupal 9 projects with a relocated document root", | |
"type": "project", | |
"license": "GPL-2.0-or-later", | |
"homepage": "https://www.drupal.org/project/drupal", | |
"support": { | |
"docs": "https://www.drupal.org/docs/user_guide/en/index.html", | |
"chat": "https://www.drupal.org/node/314178" | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_ENTITY_TYPE_presave(). | |
* | |
* Prefill cost information for events if a previous event matches the same name and presenter. | |
*/ | |
function libevents_node_presave(EntityInterface $node) { | |
$title = ''; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_ENTITY_TYPE_presave(). | |
* | |
* Prefill cost information for events if a previous event matches the same name and presenter. | |
*/ | |
function libevents_node_presave(EntityInterface $node) { | |
$title = ''; | |
$presenter = ''; |
NewerOlder