-
Iterating Entities in Drupal 8
What do you do if you need to iterate over a lot of loaded entities during a single request or background process, like a Drush command? I thought it would be as easy as this …
-
Delete Git Branches By Prefix
Here is a quick script I use to delete local git branches by a prefix. I like to branch a lot, so I usually end up with tons of branches related to tickets etc.. This provides a simple way to remove them by a particular pattern. Yes, you could just use an alias and one of the commands in the comment below. However, that does not really give you the chance to easily see the branches that will be removed and confirm. With a simple Ruby script, this can be done in a couple of minutes. Plus it’s more fun (and less eye burning than a bash script)!
Tip: Name this script
git-branch-del
so it can be invoked as a git command, likegit branch-del
. -
Drupal AJAX return content
I recently wanted to populate some content on a page via AJAX in Drupal 7. It is easy enough to just do something like this:
$.get(path, function(data, textStatus, XHR) { some_callback(data); };
Great. Everything is dandy, until the content you have
#attached
assets from the content you have rendered on the server side (or anything added withdrupal_add_(js|css|library
) too). A simple AJAX request like this will give you the generated HTML but means you cannot easily update the assets for the page and re-attach Drupal behaviors. -
Drush PHP Settings
My previous post gave an introduction to the
drush php
command and PsySH.I have not had a chance to look at integrating PsySH settings for this directly with drush settings yet. Hopefully sometime soon I will open a pull request to integrate shell settings with drush better. So for now, I just use the config file functionality that comes bundled with PsySH to add a config file. See here for more details.
-
Drepl
I see a lot of people using things like on the command line:
drush ev 'var_dump(\Drupal\user\Entity\User::load(1));'