image.drush.inc

  1. 8.0.x commands/core/image.drush.inc
  2. 6.x commands/core/image.drush.inc
  3. 7.x commands/core/image.drush.inc
  4. 4.x commands/core/image.drush.inc
  5. 5.x commands/core/image.drush.inc
  6. master commands/core/image.drush.inc

Image module's drush integration.

@todo image-build($field_name, $bundle, $style_name)

Functions

File

commands/core/image.drush.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Image module's drush integration.
  5. *
  6. * @todo image-build($field_name, $bundle, $style_name)
  7. */
  8. use Drush\Log\LogLevel;
  9. /**
  10. * Implementation of hook_drush_command().
  11. */
  12. function image_drush_command() {
  13. $items['image-flush'] = array(
  14. 'description' => 'Flush all derived images for a given style.',
  15. 'core' => array('7+'),
  16. 'arguments' => array(
  17. 'style' => 'An image style machine name. If not provided, user may choose from a list of names.',
  18. ),
  19. 'options' => array(
  20. 'all' => 'Flush all derived images',
  21. ),
  22. 'examples' => array(
  23. 'drush image-flush' => 'Pick an image style and then delete its images.',
  24. 'drush image-flush thumbnail' => 'Delete all thumbnail images.',
  25. 'drush image-flush --all' => 'Flush all derived images. They will be regenerated on the fly.',
  26. ),
  27. 'aliases' => array('if'),
  28. );
  29. $items['image-derive'] = array(
  30. 'description' => 'Create an image derivative.',
  31. 'core' => array('7+'),
  32. 'drupal dependencies' => array('image'),
  33. 'arguments' => array(
  34. 'style' => 'An image style machine name.',
  35. 'source' => 'Path to a source image. Optionally prepend stream wrapper scheme.',
  36. ),
  37. 'required arguments' => TRUE,
  38. 'options' => array(),
  39. 'examples' => array(
  40. 'drush image-derive thumbnail themes/bartik/logo.png' => 'Save thumbnail sized derivative of logo image.',
  41. ),
  42. 'aliases' => array('id'),
  43. );
  44. return $items;
  45. }
  46. /**
  47. * Implements hook_drush_help_alter().
  48. */
  49. function image_drush_help_alter(&$command) {
  50. // Drupal 8+ customizations.
  51. if ($command['command'] == 'image-derive' && drush_drupal_major_version() >= 8) {
  52. unset($command['examples']);
  53. $command['examples']['drush image-derive thumbnail core/themes/bartik/logo.png'] = 'Save thumbnail sized derivative of logo image.';
  54. }
  55. }
  56. /**
  57. * Command argument complete callback.
  58. *
  59. * @return
  60. * Array of available configuration files for editing.
  61. */
  62. function image_image_flush_complete() {
  63. drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_FULL);
  64. drush_include_engine('drupal', 'image');
  65. return array('values' => array_keys(drush_image_styles()));
  66. }
  67. function drush_image_flush_pre_validate($style_name = NULL) {
  68. drush_include_engine('drupal', 'image');
  69. if (!empty($style_name) && !$style = drush_image_style_load($style_name)) {
  70. return drush_set_error(dt('Image style !style not recognized.', array('!style' => $style_name)));
  71. }
  72. }
  73. function drush_image_flush($style_name = NULL) {
  74. drush_include_engine('drupal', 'image');
  75. if (drush_get_option('all')) {
  76. $style_name = 'all';
  77. }
  78. if (empty($style_name)) {
  79. $styles = array_keys(drush_image_styles());
  80. $choices = array_combine($styles, $styles);
  81. $choices = array_merge(array('all' => 'all'), $choices);
  82. $style_name = drush_choice($choices, dt("Choose a style to flush."));
  83. if ($style_name === FALSE) {
  84. return drush_user_abort();
  85. }
  86. }
  87. if ($style_name == 'all') {
  88. foreach (drush_image_styles() as $style_name => $style) {
  89. drush_image_flush_single($style_name);
  90. }
  91. drush_log(dt('All image styles flushed'), LogLevel::SUCCESS);
  92. }
  93. else {
  94. drush_image_flush_single($style_name);
  95. }
  96. }
  97. function drush_image_derive_validate($style_name, $source) {
  98. drush_include_engine('drupal', 'image');
  99. if (!$style = drush_image_style_load($style_name)) {
  100. return drush_set_error(dt('Image style !style not recognized.', array('!style' => $style_name)));
  101. }
  102. if (!file_exists($source)) {
  103. return drush_set_error(dt('Source file not found - !file.', array('!file' => $source)));
  104. }
  105. }
  106. /*
  107. * Command callback. Create an image derivative.
  108. *
  109. * @param string $style_name
  110. * The name of an image style.
  111. *
  112. * @param string $source
  113. * The path to a source image, relative to Drupal root.
  114. */
  115. function drush_image_derive($style_name, $source) {
  116. drush_include_engine('drupal', 'image');
  117. return _drush_image_derive($style_name, $source);
  118. }