Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@hannsen
Created February 24, 2020 09:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hannsen/a05b10b397a86c389f5983d358915724 to your computer and use it in GitHub Desktop.
Save hannsen/a05b10b397a86c389f5983d358915724 to your computer and use it in GitHub Desktop.
Drupal Cheat Sheet
all cardinality unlimited fields: entity->field->getValue()
all referenced entites: entity->field->referencedEntities()
one referenced entity: entity->field->entity
value of field: entity->field->value
entity reference id of field: entity->field->target_id
load entity by id: Entity::load(id)
load multiple entites by id: Entity::loadMultiple([ids])
clear cache: \Drupal::service('page_cache_kill_switch')->trigger();
get tabellen name of entity: ->getEntityType()->getDataTable()
https://jtreminio.com/2013/03/unit-testing-tutorial-part-4-mock-objects-stub-methods-dependency-injection/
drush cron lock remove: drush sqlq "DELETE FROM semaphore WHERE name = 'cron';"
drush windows:
vendor/bin/drush init
echo @php c:/xampp/htdocs/oequasta/vendor/drush/drush/drush %* > /c/xampp/htdocs/oequasta/vendor/drush/drush/drush.bat
unit tests: SIMPLETEST_DB="mysql://root@localhost/test" ../vendor/phpunit/phpunit/phpunit -c core/phpunit.xml.dist modules/quodata/rechnung/tests/src/Kernel/JahresrechnungenUmmeldungsTests.php
Ajax Form: secret gist
Sort Entity Refs by name:
$fields['some_entity'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Some entity'))
->setSettings([
'multiple' => TRUE,
'multiple_values' => TRUE,
'target_type' => 'some_entity',
'handler_settings' => [
'sort' => [
'field' => 'name',
'direction' => 'ASC',
],
],
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment