Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image 从DRUPAL 7上的图像中删除宽度和高度属性_Image_Drupal_Height_Width - Fatal编程技术网

Image 从DRUPAL 7上的图像中删除宽度和高度属性

Image 从DRUPAL 7上的图像中删除宽度和高度属性,image,drupal,height,width,Image,Drupal,Height,Width,如何删除Drupal 7在图像上添加的自动属性?使用Drupal 7,您只需要实现hook\u preprocess\u image(),因为预处理函数是为每个主题函数执行的,而不仅仅是使用模板文件的函数。在您的情况下,以下代码应该足够了 function mymodule_preprocess_image(&$variables) { foreach (array('width', 'height') as $key) { unset($variables[$key]);

如何删除Drupal 7在图像上添加的自动属性?

使用Drupal 7,您只需要实现
hook\u preprocess\u image()
,因为预处理函数是为每个主题函数执行的,而不仅仅是使用模板文件的函数。在您的情况下,以下代码应该足够了

function mymodule_preprocess_image(&$variables) {
  foreach (array('width', 'height') as $key) {
    unset($variables[$key]);
  }
}
由于
$variables['attributes']
还包含图像属性,因此下面的代码更完整

function mymodule_preprocess_image(&$variables) {
  $attributes = &$variables['attributes'];

  foreach (array('width', 'height') as $key) {
    unset($attributes[$key]);
    unset($variables[$key]);
  }
}
用模块/主题的短名称替换mymodule


当需要更改传递给主题函数/模板文件的变量时,最好使用预处理函数。只有在需要更改主题函数返回的输出时,才应重写主题函数。在这种情况下,您只需要更改变量,因此无需重写主题函数。使用预处理钩子,您的代码将与将来的Drupal版本兼容。

您的意思是“theme_image()”?!因为我不认为drupal中有一个名为hook_preprocess_image()的函数,hook_preprocess_image()是用于主题图像()的预处理函数,同样地,
hook_preprocess_node()
是主题节点()的预处理函数。你永远不应该编辑Drupal主题函数。我不是说编辑theme_image(),为什么我们不能在template.php文件“类似于:MyTheme_image()”中使用它呢。这样比较容易-穆罕默德。请看我的答案的最后三句,这是最新的。谢谢你,正是我所需要的!