12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- /**
- * @file
- * Drush commands for the blog module.
- */
- use Drupal\dr8_zth\Entity\Blog;
- /**
- * Implements hook_drush_command().
- */
- function blog_drush_command() {
- $ret['blog-create'] = [
- 'description' => 'Create a blog entity',
- ];
- $ret['blog-create-values'] = [
- 'description' => 'Create a blog entity with values',
- ];
- $ret['blog-delete'] = [
- 'description' => 'Delete a blog entity by its id',
- ];
- $ret['blog-load'] = [
- 'description' => 'Load a blog entity by its id',
- ];
- return $ret;
- }
- /**
- * Command callback for blog-create.
- */
- function drush_blog_create() {
- $blog = Blog::create();
- $blog->save();
- }
- /**
- * Command callback for blog-create-values.
- */
- function drush_blog_create_values() {
- $values = [
- 'title' => 'Drupal user group',
- 'date' => (new \DateTime())->format(DATETIME_DATETIME_STORAGE_FORMAT),
- 'description' => [
- 'value' => '<p>The monthly meeting of Drupalists is happening today!</p>',
- 'format' => 'restricted_html',
- ],
- ];
- $blog = Blog::create($values);
- $blog->save();
- }
- /**
- * Command callback for blog-delete.
- *
- * @param int $id
- * The id of a blog to delete.
- */
- function drush_blog_delete($id) {
- $blog = Blog::load($id);
- if (!$blog) {
- return;
- }
- $blog->delete();
- }
- /**
- * Command callback for blog-delete.
- *
- * @param int $id
- * The id of a blog to load and display.
- */
- function drush_blog_load($id) {
- $blog = Blog::load($id);
- if (!$blog) {
- return;
- }
- echo "Blog id: " . $blog->id() . ", uuid: " . $blog->uuid() . "\n";
- print_r($blog->toArray());
- }
|