Key Differences Between Drupal 7 and Drupal 8+
Let’s break down some key differences between Drupal 7 and Drupal 8+:
Templating Engine:
Drupal 7: PHP Template
Drupal 8+: Twig template engine (more secure and flexible!)
Programming Paradigm:
Drupal 7: Traditional PHP
Drupal 8+: Object-oriented programming with Symfony components for a modern architecture!
Configuration Management:
Drupal 7: Lacks native configuration management
Drupal 8+ delete node using some criteria programmatically
Here are the two methods to delete the nodes in Drupal 8 programmatically.
1) Using NID
use Drupal\node\Entity\Node;
$nid = 123;
$node = Node::load($nid);
// or
$node = \Drupal::entityTypeManager()->getStorage('node')->load($nid);
// Check if node exists with the given nid.
if ($node) {
$node->delete();
}
2) Using some criteria (for example, older than 90 days)
Delete All nodes of specific content type programmatically drupal 8+
This is mainly for deleting all testing data that you may have created using devel generate module or similar to it
If you have devel php installed in your drupal site you can directly run this is the browser or you may have to use it in the custom module
I would recommend to use devel php module as it is much simpler and easy to use just make sure you don't have devel modules in your production environment and if you need to delete nodes in the production then just install devel to run this code and then uninstall
Multisite folder structure in Drupal 8+
Following is an example of the multisite structure with Drupal. For simplicity, other Drupal core folders and files are not listed.
How to create a Media video youtube entity programmatically drupal 8+
The example above assumes that you have the video file ID. This could be the case when you are converting video fields to media.
To do this you have to use the Remote video media type.
use Drupal\media\Entity\Media;
$video_media = Media::create([
'bundle' => 'remote_video',
'uid' => 1,
'name' => 'DrupalCon Prague 2022 Driesnote',
'field_media_oembed_video' => [
'value' => 'https://www.youtube.com/watch?v=Hmit4ET-l3Q',
],
]);
$video_media->save();
Create media image programmatically in Drupal 8+
Using Media in Drupal (versions 8+) is a much better option than using old-school image fields. You can add all types of fields to Media to enrich your images, videos, and other media types with additional information, and you can also reuse Media. All of that cannot be easily done if you are using regular image fields.
Just like Content types, you can have multiple different types of Media. By default when you enable the Media module you get the following types:
How to Load Node, File, Taxonomy Entities by ID in Drupal 8+
To load node details using its id in Drupal 8+ uses the following syntax:
$node_details = Node::load($nid);
$node_details->field_FIELD_NAME->value;
We can load multiple nodes in Drupal 8+ using load multiple() function. Note that the parameter should be an array of ids.
Configure and Display a Schedule of Opening Hours in PHP
Opening Hours is a PHP package by Spatie to query and format a set of business operating hours. You can use it to present the times per day and include exceptions for things like holidays and other days off on a given year-specific date or recurring (happening each year). The project's readme file has this example to illustrate how you can configure hours:
LangCountry is a Localization Package for Laravel
The Laravel LangCountry is a localization package that provides automatic date formatting, language switching, and more. Defining language detection and configuration can be tedious, so this package can make it easier to support multiple locales and the following feature list:
Building a Sitemap in your Laravel app with the Spatie Sitemap
According to Google, most sites would benefit from a sitemap, which helps bots know what pages should be crawled.
A sitemap is a file where you provide information about the pages, videos, and other files on your site, and the relationships between them. Search engines like Google read this file to crawl your site more efficiently. A sitemap tells Google which pages and files you think are important in your site, and also provides valuable information about these files. For example, when the page was last updated and any alternate language versions of the page.