Wednesday, August 21, 2019
access taxonomy fields programatically in drupal 8
Access one term:
$term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->load(TID);
$value = $term->FIELD_MACHINENAME->value;
Example : load title and language of term id =2 $term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->load(2);
$title = $term->name->value;
langcode = $term->langcode->value;
And for load Multiple $terms = $entityManager->getStorage('taxonomy_term')->loadMultiple($terms);
foreach ($terms as $term) {
var_dump($term->tid->value); //return tid of term
var_dump($term->name->value); //return title of term
}
Tuesday, July 2, 2019
Tuesday, June 25, 2019
Migration path info for drupal 8
if the path of your csv file is in the root of your project then:
source:
plugin: CSV
path: your_file.csv
the best practice is to put the csv file into your migrate module in a directory "artifacts" for example the structure should be as below:
-- custom_migrate_module
+-- artifacts
+-- your_file.csv
+-- config
+-- src
+-- custom_migrate_module.info.yml
in this case your migration confg file should be:
source:
plugin: CSV
path: modules/custom/custom_migrate_module/artifacts/your_file.csv
Thursday, June 13, 2019
Useful Drupal 8 modules
1. Conditional Fields - Allows for easy creation of conditional fields for content types.
Tuesday, June 11, 2019
find unprintable characters in vim
Using range in a [] character class in your search, you ought to be able to exclude the ASCII hexadecimal character range, therefore highlighting (assuming you have hlsearch enabled) all other characters lying outside the ASCII range:
/[^\x00-\x7F]
This will do a negative match (via [^]) for characters between ASCII 0x00 and ASCII 0x7F (0-127), and appears to work in my simple test. For extended ASCII, of course, extend the range up to \xFF instead of \x7F using /[^\x00-\xFF].
You may also express it in decimal via \d:
/[^\d0-\d127]
If you need something more specific, like exclusion of non-printable characters, you will need to add those ranges into the character class [].
/[^\x00-\x7F]
This will do a negative match (via [^]) for characters between ASCII 0x00 and ASCII 0x7F (0-127), and appears to work in my simple test. For extended ASCII, of course, extend the range up to \xFF instead of \x7F using /[^\x00-\xFF].
You may also express it in decimal via \d:
/[^\d0-\d127]
If you need something more specific, like exclusion of non-printable characters, you will need to add those ranges into the character class [].
Thursday, June 6, 2019
Search through Git logs!
Taken from: https://www.gun.io/blog/git-search-log
So, you want to search your git commit logs. Good news! It's really easy, and I'm going to show you how to do it.
If you use git, you're probably already familiar with the classic UNIX string searching tool, 'grep.' (If you already know about grep but want something better, you should try out Ack, but that's an unrelated issue.)
Lucky for you, git has a 'grep' mode!
Suppose I wanted to search for the string "facebook" in all of the commit messages of my project. All it takes is this one command:
git log --grep="facebook"
and you'll see all of the log messages which contain the our search term!
Okay, now suppose that you want to search more than just the commit messages, but the commits themselves. Simple! Drop the 'log' argument.
git grep "facebook" $(git rev-list --all)
This will show the commit ID and line number of all instances of your string. (The string can also be a regular expression, which is handy if you know regex, too.)
This can be made slightly more human-friendly by using the 'pickaxe' feature of git log grep, like this:
git log -S"facebook"
which will show all the commit messages of commits which include your string.
Hope this helped!
Monday, June 3, 2019
Unable to install , already exists in active configuration.
When I come accross this error: Unable to install <module>, <config name> already exists in active configuration.
Try this:
Try this:
fin drush config:delete <config name>
Tuesday, May 28, 2019
Thursday, May 16, 2019
To obliterate your branch if you have messed it up beyond recognition
git checkout mybranch
git reset --hard origin/mybranch
Tuesday, May 7, 2019
Docksal Fixing
fin vm remove is a good last resort command to fix problems that are not fixed by fin vm restart
Friday, April 26, 2019
Repair GIT Permissions
Repair Permissions
After you have identified and fixed the underlying cause (see below), you'll want to repair the permissions:
cd /path/to/repo.git
sudo chgrp -R groupname .
sudo chmod -R g+rwX .
find . -type d -exec chmod g+s '{}' +
Note if you want everyone to be able to modify the repository, you don't need the
chgrp and you will want to change the chmod to sudo chmod -R a+rwX .
Friday, March 29, 2019
REALLY GOOD way of getting a median from a MYSQL query
SET @r = 0;
SELECT ROUND(AVG(LAT_N), 4) FROM (SELECT LAT_N, (@r := @r + 1) AS r FROM STATION ORDER BY LAT_N) TEMP
WHERE
r = (SELECT CEIL(COUNT(*) / 2) FROM STATION) OR
r = (SELECT FLOOR(COUNT(*) / 2 + 1) FROM STATION)
SELECT ROUND(AVG(LAT_N), 4) FROM (SELECT LAT_N, (@r := @r + 1) AS r FROM STATION ORDER BY LAT_N) TEMP
WHERE
r = (SELECT CEIL(COUNT(*) / 2) FROM STATION) OR
r = (SELECT FLOOR(COUNT(*) / 2 + 1) FROM STATION)
Wednesday, January 30, 2019
Can't get to needed tags in a Drupal twig file? Make another twig file that is closer to the desired content.
Can't get to needed tags in a Drupal twig file? Make another twig file that is closer to the desired content.
Wednesday, January 23, 2019
Good way to do git revert
UPDATE: This probably isn't as good:
I have found that doing
git revert --no-commit HEAD~(number of commits back)..
for example:
git revert --no-commit HEAD~3..
and then committing the changes is a great way to revert back to a previous commit without messing up git structure.
UPDATE: This is better:
git reset --hard (hash number) deletes all changes and goes straight to that commit.
git revert (hash number) allows you to merge changes made in that revision with the HEAD
I have found that doing
git revert --no-commit HEAD~(number of commits back)..
for example:
git revert --no-commit HEAD~3..
and then committing the changes is a great way to revert back to a previous commit without messing up git structure.
UPDATE: This is better:
git reset --hard (hash number) deletes all changes and goes straight to that commit.
git revert (hash number) allows you to merge changes made in that revision with the HEAD
Drupal 8 - Make sure to use if statements in hooks
When using a hook in drupal, be sure to use an if statement to assure that what you want to work with is present. The hook applies to everything on the site, and may cause issues if you are not thinking about that.
Subscribe to:
Posts (Atom)