This file contains hidden or 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
$terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree('categories'); | |
if (!empty($terms)) { | |
foreach($terms as $term) { | |
// do whatever with $term here. | |
} | |
} |
This file contains hidden or 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 | |
/** | |
* Format number as ordinal. | |
* | |
* @param string $number | |
* The unformatted number. | |
* | |
* @return string | |
* The ordinal number. |
This file contains hidden or 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
composer global require drush/drush:7.* | |
# Now add ~/.composer/vendor/bin to your $PATH in ~/.bashrc, like so: | |
# export PATH="/home/ubuntu/.composer/vendor/bin:$PATH" |
This file contains hidden or 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 | |
/** | |
* Implements hook_theme(). | |
* | |
* Note that this isn't necessary if the template is in the site theme rather than a module. | |
* See https://www.drupal.org/docs/8/theming/twig/twig-template-naming-conventions | |
*/ | |
function my_module_theme($existing, $type, $theme, $path) { | |
return array( |
This file contains hidden or 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 | |
* Defines a dropdown widget for integer fields. | |
*/ | |
namespace Drupal\nba_content_core\Plugin\Field\FieldWidget; | |
use Drupal\Core\Field\FieldFilteredMarkup; | |
use Drupal\Core\Field\FieldItemListInterface; |
This file contains hidden or 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
sudo apt-get update | |
sudo apt-get install php-pear php5-dev php5-mcrypt | |
sudo php5enmod mcrypt | |
sudo pecl install xhprof-beta | |
echo "extension=xhprof.so" > /tmp/xhprof.ini | |
sudo mv /tmp/xhprof.ini /etc/php5/mods-available/ | |
sudo php5enmod xhprof | |
sudo service apache2 restart | |
# Now run `php --ri xhprof` to confirm that the install worked. |
This file contains hidden or 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
drush ev '\Drupal::service("router.builder")->rebuild();' |
This file contains hidden or 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 | |
$path = \Drupal::service('path.alias_manager')->getPathByAlias('/this-is-the-alias'); | |
if(preg_match('/node\/(\d+)/', $path, $matches)) { | |
$node = \Drupal\node\Entity\Node::load($matches[1]); | |
} |
This file contains hidden or 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 | |
$request = \Drupal::request(); | |
$controller_resolver = \Drupal::getContainer()->get('controller_resolver'); | |
$controller = $controller_resolver->getController($request); | |
if (!empty($controller)) { | |
$controller_instance = $controller[0]; | |
// Now you can call things like this: |
This file contains hidden or 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 | |
$formatter = new NumberFormatter('en_US', NumberFormatter::ORDINAL); | |
print $formatter->format($number); |