blog.drush.inc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * @file
  4. * Drush commands for the blog module.
  5. */
  6. use Drupal\dr8_zth\Entity\Blog;
  7. /**
  8. * Implements hook_drush_command().
  9. */
  10. function blog_drush_command() {
  11. $ret['blog-create'] = [
  12. 'description' => 'Create a blog entity',
  13. ];
  14. $ret['blog-create-values'] = [
  15. 'description' => 'Create a blog entity with values',
  16. ];
  17. $ret['blog-delete'] = [
  18. 'description' => 'Delete a blog entity by its id',
  19. ];
  20. $ret['blog-load'] = [
  21. 'description' => 'Load a blog entity by its id',
  22. ];
  23. return $ret;
  24. }
  25. /**
  26. * Command callback for blog-create.
  27. */
  28. function drush_blog_create() {
  29. $blog = Blog::create();
  30. $blog->save();
  31. }
  32. /**
  33. * Command callback for blog-create-values.
  34. */
  35. function drush_blog_create_values() {
  36. $values = [
  37. 'title' => 'Drupal user group',
  38. 'date' => (new \DateTime())->format(DATETIME_DATETIME_STORAGE_FORMAT),
  39. 'description' => [
  40. 'value' => '<p>The monthly meeting of Drupalists is happening today!</p>',
  41. 'format' => 'restricted_html',
  42. ],
  43. ];
  44. $blog = Blog::create($values);
  45. $blog->save();
  46. }
  47. /**
  48. * Command callback for blog-delete.
  49. *
  50. * @param int $id
  51. * The id of a blog to delete.
  52. */
  53. function drush_blog_delete($id) {
  54. $blog = Blog::load($id);
  55. if (!$blog) {
  56. return;
  57. }
  58. $blog->delete();
  59. }
  60. /**
  61. * Command callback for blog-delete.
  62. *
  63. * @param int $id
  64. * The id of a blog to load and display.
  65. */
  66. function drush_blog_load($id) {
  67. $blog = Blog::load($id);
  68. if (!$blog) {
  69. return;
  70. }
  71. echo "Blog id: " . $blog->id() . ", uuid: " . $blog->uuid() . "\n";
  72. print_r($blog->toArray());
  73. }