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\custom_config_form\Form; | |
use Drupal\Core\Form\ConfigFormBase; | |
use Drupal\Core\Form\FormStateInterface; | |
/** | |
* Configure Custom Config Form settings for this site. | |
*/ |
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 | |
/** | |
* @file | |
* Primary module hooks for Custom Template module. | |
*/ | |
/** | |
* Implements hook_theme(). | |
*/ |
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\custom_drush_command\Commands; | |
use Consolidation\OutputFormatters\StructuredData\RowsOfFields; | |
use Drush\Commands\DrushCommands; | |
/** | |
* A Drush commandfile. | |
* |
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\custom_controller\Controller; | |
use Drupal\Core\Controller\ControllerBase; | |
/** | |
* Returns responses for Custom Controller routes. | |
*/ | |
class CustomControllerController extends ControllerBase { |
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 | |
/** | |
* @file | |
* Install, update and uninstall functions for the modulename module. | |
*/ | |
/** | |
* Implements hook_schema(). |
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 | |
In the submitForm() method of your form class, create a new instance of the RedirectResponse class, which is used to redirect to a new URL. | |
// Use the setRedirectUrl() method to set the URL to which you want to redirect. You can pass the URL as a string or as an instance of the Url class. | |
// Return the RedirectResponse object from the submitForm() method to trigger the redirect. | |
// Here's an example of how to use setRedirectUrl() in a form class: | |
use Drupal\Core\Form\FormStateInterface; | |
use Drupal\Core\Routing\RedirectDestinationInterface; |
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 | |
// Named arguments were introduced in PHP 8, | |
// and they allow you to pass arguments to a function or method by specifying the name of the argument | |
// rather than relying on the order in which the arguments are defined. | |
// Here's an example of using named arguments in PHP: | |
function createUser($name, $email, $age) { | |
echo "Name: $name <br>"; |
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 | |
// The splat operator (also known as the variadic operator) in PHP is represented by three dots (...) | |
// It allows you to pass an arbitrary number of arguments to a function or method. | |
// Here's an example of using the splat operator in PHP: | |
function addNumbers(...$numbers) { | |
$sum = 0; | |
foreach ($numbers as $number) { | |
$sum += $number; |
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 | |
/** | |
* Generic function to direct download any type of file. | |
*/ | |
function directDownloadAnyFile($file, $newfilename = '', $mimetype='', $isremotefile = false) { | |
$formattedhpath = ""; | |
$filesize = ""; |
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 | |
use Drupal\media\Entity\Media; | |
use Drupal\file\Entity\File; | |
use Drupal\Core\Url; | |
// Load the media | |
$media_id = <Replace with the id of media entity>; | |
$media = Media::load($media_id); | |
// Get file id from the media. |
OlderNewer