Drupal instance of Drupal \ path_alias \ AliasManager given
I'm receiving an error with a path of Drupal\path_alias\AliasManager
Upgrading to Drupal 9, I was running a test to see which blocks and/or modules would fail. And there were plenty... like this AliasManager error
twig add to array [merge, append, push]
Working in Twig, I had to add classes to a pre-existing array. Whilst I've grown used to the patterns in PHP, these cannot be applied in Twig. Instead I had to merge the new array elements.
Non associative arrays
Working from a base level, I'll begin as if the original array hasn't been set. The merge filter expects as first argument an array whose content will be merged with the assigned variable:
Drupal resolving a white screen of death
On a git pull from remote dev environment to a staging environment running off AWS server... I was greeted with the white screen of death. While it took me a while to resolve the actual issue, my action plan was as follows:
How to resolve:
- Look in your log files;
- Add a few lines to your index.php file
Drupal URL links programmatically
Creating URL's in Drupal programmatically:
Internal path
use Drupal\Core\Link;
use Drupal\Core\Url;
$internal_link = Link::fromTextAndUrl(t('Drupal nodes'), Url::fromUri('internal:/node', $options))->toString();
External Url
use Drupal\Core\Link;
use Drupal\Core\Url;
$external_link = Link::fromTextAndUrl(t('Codebales'), Url::fromUri('http://www.codebales.com/'))->toString();
Solving the Error: Call to a member function getFileUri() on null
I was trying to create something quite simple. How to get image file uri from media entity id or rendered entity.
Or other variations you might have searched:
- How to load existing media programmatically
- How to get image file uri from media entity id
- Call to a member function getFileUri()
- drupal File::load getFileUri
- drupal getFileUri
Drupal twig look up to access field data
This guide has been compiled as a reference tool on how to access field values for different field types.
The Manage Display admin UI can change how a field’s label and content are displayed. When I want to show how to output just the Manage Display version of the content, I use the word ‘display’. When I’m talking about the more raw version of the content, I use ‘value’.
Mismatched entity and/or field definitions
Have you come across the following Drupal error message:
Mismatched entity and/or field definitions. The following changes were detected in the entity type and field definitions.
Run a database update status check
drush updatedb:status --entity-updatesResponse
common Drush commands
If your Composer project doesn't have Drush listed as a dependency, you can install Drush from command line as follows:
composer require drush/drushTo check your version of Drush, use
drush --version
Status check
drush statusWill output something similar to
Setting up a new local site environment
Setting up a new project in Docker and VS Code.
Using Terminal, go to your Sites directory and create a new directory using the mkdir command. In this instance I'm going to create a new directory titled ADCE
shortcut command to access the Sites directory
cd ~/Sites
Create the new directory
mkdir ADCE
Go in to the new directory
cd ADCE
Run the devcontainer command
How to programmatically create a custom Drupal 8 block
Blocks are a great way to add pieces or chunks of content to your Drupal site. Capable of displaying simple text, images, forms or complex logic. There are plenty of sites around that show you how to add a simple custom block. However, if you are a developer like me, when you are writing your custom block programmatically it has far more requirements than a simple block. In this article, I'll show how to: