Skip to content

Instantly share code, notes, and snippets.

@timonweb
Forked from facine/__INDEX.txt
Created July 6, 2016 13:05

Revisions

  1. @facine facine revised this gist Nov 9, 2015. 4 changed files with 8 additions and 8 deletions.
    2 changes: 1 addition & 1 deletion create_menu_link.php
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@
    ]);
    $menu_item->save();

    $menu_item_es = $menu_item->getTranslation('es');
    $menu_item_es = $menu_item->addTranslation('es');
    $menu_item_es->title = 'Mi enlace del menú';
    $menu_item_es->description = 'Mi descripción.';
    $menu_item_es->save();
    6 changes: 3 additions & 3 deletions create_node.php
    Original file line number Diff line number Diff line change
    @@ -21,11 +21,11 @@
    ],
    ]);
    $node->save();
    \Drupal::service('path.alias_storage')->save("node/" . $node->id(), "my/path", "en");
    \Drupal::service('path.alias_storage')->save("/node/" . $node->id(), "/my/path", "en");

    $node_es = $node->getTranslation('es');
    $node_es = $node->addTranslation('es');
    $node_es->title = 'Mi prueba!';
    $node_es->body->value = '<p>El cuerpo de mi nodo.</p>';
    $node_es->body->format = 'full_html';
    $node_es->save();
    \Drupal::service('path.alias_storage')->save("node/" . $node->id(), "mi/ruta", "es");
    \Drupal::service('path.alias_storage')->save("/node/" . $node->id(), "/mi/ruta", "es");
    2 changes: 1 addition & 1 deletion create_node_with_image.php
    Original file line number Diff line number Diff line change
    @@ -32,4 +32,4 @@
    ],
    ]);
    $node->save();
    \Drupal::service('path.alias_storage')->save('node/' . $node->id(), 'my-path', 'en');
    \Drupal::service('path.alias_storage')->save('/node/' . $node->id(), '/my-path', 'en');
    6 changes: 3 additions & 3 deletions create_taxonomy_term.php
    Original file line number Diff line number Diff line change
    @@ -15,11 +15,11 @@
    'parent' => array (0);
    ]);
    $term->save();
    \Drupal::service('path.alias_storage')->save("taxonomy/term/" . $term->id(), "tags/my-tag", "en");
    \Drupal::service('path.alias_storage')->save("/taxonomy/term/" . $term->id(), "/tags/my-tag", "en");

    $term_es = $term->getTranslation('es');
    $term_es = $term->addTranslation('es');
    $term_es->name = 'Mi etiqueta';
    $term_es->description->value = '<p>Mi descripción.</p>';
    $term_es->description->format = 'full_html';
    $term_es->save();
    \Drupal::service('path.alias_storage')->save("taxonomy/term/" . $term->id(), "etiquetas/mi-etiqueta", "es");
    \Drupal::service('path.alias_storage')->save("/taxonomy/term/" . $term->id(), "/etiquetas/mi-etiqueta", "es");
  2. @facine facine revised this gist Jun 12, 2015. 1 changed file with 14 additions and 0 deletions.
    14 changes: 14 additions & 0 deletions __INDEX.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    # Taxonomy terms:
    - https://gist.github.com/facine/35bb291811c146b6fc9e#file-create_taxonomy_term-php

    # Menu links:
    - https://gist.github.com/facine/35bb291811c146b6fc9e#file-create_menu_link-php

    # File items:
    - https://gist.github.com/facine/35bb291811c146b6fc9e#file-create_file-php

    # Nodes:
    # Simple node:
    - https://gist.github.com/facine/35bb291811c146b6fc9e#file-create_node-php
    # Node with image field:
    - https://gist.github.com/facine/35bb291811c146b6fc9e#file-create_node_with_image-php
  3. @facine facine revised this gist Jun 12, 2015. 2 changed files with 46 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions create_file.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    <?php
    // Programmatically create files.
    use Drupal\file\Entity\File;

    $file = File::create([
    'uid' => 1,
    'filename' => 'logo.svg',
    'uri' => 'public://page/logo.svg',
    'status' => 1,
    ]);
    $file->save();
    35 changes: 35 additions & 0 deletions create_node_with_image.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    <?php
    // Programmatically create node with image fields.
    use Drupal\file\Entity\File;
    use Drupal\node\Entity\Node;

    $file = File::create([
    'uid' => 1,
    'uri' => 'public://page/logo.png',
    'status' => 1,
    ]);
    $file->save();

    $node = Node::create([
    'type' => 'article',
    'langcode' => 'en',
    'created' => REQUEST_TIME,
    'changed' => REQUEST_TIME,
    'uid' => 1,
    'title' => 'My title',
    'field_tags' =>[2],
    'body' => [
    'summary' => '',
    'value' => 'My node!',
    'format' => 'full_html',
    ],
    'field_images' => [
    [
    'target_id' => $file->id(),
    'alt' => "My 'alt'",
    'title' => "My 'title'",
    ],
    ],
    ]);
    $node->save();
    \Drupal::service('path.alias_storage')->save('node/' . $node->id(), 'my-path', 'en');
  4. @facine facine revised this gist Jun 12, 2015. 3 changed files with 33 additions and 3 deletions.
    1 change: 1 addition & 0 deletions create_menu_link.php
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    <?php
    // Programmatically create and translate menu links.
    use Drupal\menu_link_content\Entity\MenuLinkContent;

    31 changes: 31 additions & 0 deletions create_node.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    <?php
    // Programmatically create and translate nodes.

    use Drupal\node\Entity\Node;

    $node = Node::create([
    // The node entity bundle.
    'type' => 'article',
    'langcode' => 'en',
    'created' => REQUEST_TIME,
    'changed' => REQUEST_TIME,
    // The user ID.
    'uid' => 1,
    'title' => 'My test!',
    // An array with taxonomy terms.
    'field_tags' =>[2],
    'body' => [
    'summary' => '',
    'value' => '<p>The body of my node.</p>',
    'format' => 'full_html',
    ],
    ]);
    $node->save();
    \Drupal::service('path.alias_storage')->save("node/" . $node->id(), "my/path", "en");

    $node_es = $node->getTranslation('es');
    $node_es->title = 'Mi prueba!';
    $node_es->body->value = '<p>El cuerpo de mi nodo.</p>';
    $node_es->body->format = 'full_html';
    $node_es->save();
    \Drupal::service('path.alias_storage')->save("node/" . $node->id(), "mi/ruta", "es");
    4 changes: 1 addition & 3 deletions create_taxonomy_term.php
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    <?php
    // Programmatically create and translate taxonomy terms.

    use Drupal\taxonomy\Entity\Term;
    @@ -22,6 +23,3 @@
    $term_es->description->format = 'full_html';
    $term_es->save();
    \Drupal::service('path.alias_storage')->save("taxonomy/term/" . $term->id(), "etiquetas/mi-etiqueta", "es");

    unset($term);
    unset($term_es);
  5. @facine facine revised this gist Jun 9, 2015. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions create_taxonomy_term.php
    Original file line number Diff line number Diff line change
    @@ -11,6 +11,7 @@
    'format' => 'full_html',
    ],
    'weight' => -1
    'parent' => array (0);
    ]);
    $term->save();
    \Drupal::service('path.alias_storage')->save("taxonomy/term/" . $term->id(), "tags/my-tag", "en");
  6. @facine facine revised this gist Jun 9, 2015. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion create_taxonomy_term.php
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,8 @@

    $term_es = $term->getTranslation('es');
    $term_es->name = 'Mi etiqueta';
    $term_es->description['value'] = '<p>Mi descripción.</p>';
    $term_es->description->value = '<p>Mi descripción.</p>';
    $term_es->description->format = 'full_html';
    $term_es->save();
    \Drupal::service('path.alias_storage')->save("taxonomy/term/" . $term->id(), "etiquetas/mi-etiqueta", "es");

  7. @facine facine revised this gist Jun 9, 2015. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions create_taxonomy_term.php
    Original file line number Diff line number Diff line change
    @@ -6,16 +6,18 @@
    'vid' => 'sport_activity',
    'langcode' => 'en',
    'name' => 'My tag',
    'description' => '<p>My description.</p>',
    'format' => 'full_html',
    'description' => [
    'value' => '<p>My description.</p>',
    'format' => 'full_html',
    ],
    'weight' => -1
    ]);
    $term->save();
    \Drupal::service('path.alias_storage')->save("taxonomy/term/" . $term->id(), "tags/my-tag", "en");

    $term_es = $term->getTranslation('es');
    $term_es->name = 'Mi etiqueta';
    $term_es->description = '<p>Mi descripción.</p>';
    $term_es->description['value'] = '<p>Mi descripción.</p>';
    $term_es->save();
    \Drupal::service('path.alias_storage')->save("taxonomy/term/" . $term->id(), "etiquetas/mi-etiqueta", "es");

  8. @facine facine revised this gist Jun 9, 2015. 1 changed file with 19 additions and 0 deletions.
    19 changes: 19 additions & 0 deletions create_menu_link.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    // Programmatically create and translate menu links.
    use Drupal\menu_link_content\Entity\MenuLinkContent;

    $menu_item = MenuLinkContent::create([
    'bundle' => 'menu_link_content',
    'langcode' => 'en',
    'title' => 'My menu link',
    'description' => 'My description.',
    'menu_name' => 'main',
    'link' => [['uri' => 'internal:/taxonomy/term/15']],
    'parent' => 'menu_link_content:c8859c9c-a550-45a9-a705-5d032dee525c',
    'weight' => 0,
    ]);
    $menu_item->save();

    $menu_item_es = $menu_item->getTranslation('es');
    $menu_item_es->title = 'Mi enlace del menú';
    $menu_item_es->description = 'Mi descripción.';
    $menu_item_es->save();
  9. @facine facine created this gist Jun 9, 2015.
    23 changes: 23 additions & 0 deletions create_taxonomy_term.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    // Programmatically create and translate taxonomy terms.

    use Drupal\taxonomy\Entity\Term;

    $term = Term::create([
    'vid' => 'sport_activity',
    'langcode' => 'en',
    'name' => 'My tag',
    'description' => '<p>My description.</p>',
    'format' => 'full_html',
    'weight' => -1
    ]);
    $term->save();
    \Drupal::service('path.alias_storage')->save("taxonomy/term/" . $term->id(), "tags/my-tag", "en");

    $term_es = $term->getTranslation('es');
    $term_es->name = 'Mi etiqueta';
    $term_es->description = '<p>Mi descripción.</p>';
    $term_es->save();
    \Drupal::service('path.alias_storage')->save("taxonomy/term/" . $term->id(), "etiquetas/mi-etiqueta", "es");

    unset($term);
    unset($term_es);