Drupal 8 For Absolute Beginners
Check out the Drupal 8 book written by barnettech and web tech kitchen and is published by Apress Media. The book is now available on Amazon.com and in bookstores (possibly if there are any old school bookstores left selling technology books) http://amzn.to/1FDe3mZ
Here's the official write up advertising the book, screenshot at the bottom of this post:
programmatically save a taxonomy term
$node = Node::create(array( 'type' => 'article', 'title' => 'My Title', 'langcode' => 'en', 'uid' => '1', 'status' => 1, 'created' => $data[$dateIndex], 'field_autor' => $data[$autorIndex], 'field_teaser_text' => $data[$shortIndex], 'field_mytaxonomy' => [ ['target_id' => 12345] ] )); $node->save();
Drupal 8 basic query work
$connection = \Drupal::database(); $query = $connection->query("SELECT * FROM {node} n WHERE type > :type", [ ':type' => 'article', ]); $result = $query->fetchAll(); foreach ($result as $item) { $node = \Drupal\node\Entity\Node::load($item->nid); //dpm($node); $title = $node->get('title')->getValue(); $title = $title[0]['value']);
Drupal 8 programmatically create watchdog logger
\Drupal::logger('my_module')->notice($message);
to up the memory limit for drush 9
if (PHP_SAPI === 'cli') { ini_set('memory_limit', '512M'); }
Return HTML from a Drupal 8 form
<?php /** * @file * Contains \Drupal\flippersearch\Form\flippersearch. */ namespace Drupal\flippersearch\Form; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; class flippersearch extends FormBase { /** * {@inheritdoc} */ public function getFormId() { return 'flippersearch_form'; } /** * {@inheritdoc} * * @param \Symfony\Component\HttpFoundation\Request $request * The request object. */ public function buildForm(array $form, FormStateInterface $form_state) { // Use the Form API to define form elements.
invoke a form to display programmatically in Drupal 8
invoke a form within a block or custom module page
$form = \Drupal::formBuilder()->getForm('Drupal\example\Form\ExampleForm');
Getting text / a string from SimpleXMLElement Object
if (file_exists(drupal_get_path('module', 'complimentmigration') . '/MyManual08-088-18.xml')) { $xml = simplexml_load_file(drupal_get_path('module', 'complimentmigration') . '/MyManual08-088-18.xml'); $xml2 = (string) $xml->section->version->title; drupal_set_message('' . print_r($xml2, TRUE) . '');
}
reference: https://stackoverflow.com/questions/2867575/get-value-from-simplexmlele…
Download modules using composer
composer require drupal/search_api_solr or composer require --dev drupal/taxonomy_delete drush en -y search_api_solr drush cache-rebuild