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-updates
Response
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/drush
To check your version of Drush, use
drush --version
Status check
drush status
Will output something similar to
Applying a container using Docker
Running Docker in a new process and creating a container.
Go to the directory using the cd command. In this instance in the sites directory:
cd ~/Sites
Create a new directory, which can be achieved using mkdir
mkdir mydir
If Docker has been installed then the next command will be all that is required
devcontainer
How to solve "The provided host name is not valid for this server" in Drupal
Don't worry this is an issue that many Drupal developers have come across. In particular it raises its head when you add a subdomain. Your Drupal website is only showing a plain white screen with “The provided host name is not valid for this server" on it. What does it mean and how to fix it.