Всем привет!
Пытаюсь создать новый тип поля для Статьи (drupal 7). Новое поле использует существующий виджет Image.
На сервер картинка загружается. Но при просмотре статьи не отображается. Может быть кто-нибудь знает как исправить?
У меня apache 2.4/php 7/mysql 5
Вот код для создания поля:
<?php
function my_watermark_field_info()
{
return array(
'my_watermark_image_with_watermark' => array(
'label' => t('Image with watermark'),
'description' => t('Demonstrates a field composed of an RGB color.'),
'settings' => array(
'uri_scheme' => variable_get('file_default_scheme', 'public'),
'default_image' => 0,
),
'instance_settings' => array(
'file_extensions' => 'png gif jpg jpeg',
'file_directory' => '',
'max_filesize' => '',
'alt_field' => 0,
'title_field' => 0,
'max_resolution' => '',
'min_resolution' => '',
'default_image' => 0,
),
'default_widget' => 'image_image',
'default_formatter' => 'image',
)
);
}
/**
* Implements hook_field_widget_info_alter().
*/
function my_watermark_field_widget_info_alter(&$info)
{
$info['image_image']['field types'][] = 'my_watermark_image_with_watermark';
}
/**
* Implements hook_field_formatter_info_alter().
*/
function my_watermark_field_formatter_info_alter(&$info)
{
$info['image']['field types'][] = 'my_watermark_image_with_watermark';
}
/**
* Implements hook_field_load().
*/
function my_watermark_field_load($entity_type, $entities, $field, $instances, $langcode, &$items, $age)
{
file_field_load($entity_type, $entities, $field, $instances, $langcode, $items, $age);
}
/**
* Implements hook_field_prepare_view().
*/
function my_watermark_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items)
{
// If there are no files specified at all, use the default.
foreach ($entities as $id => $entity)
{
if (empty($items[$id]))
{
$fid = 0;
// Use the default for the instance if one is available.
if (!empty($instances[$id]['settings']['default_image']))
{
$fid = $instances[$id]['settings']['default_image'];
}
// Otherwise, use the default for the field.
elseif (!empty($field['settings']['default_image']))
{
$fid = $field['settings']['default_image'];
}
// Add the default image if one is found.
if ($fid && ($file = file_load($fid)))
{
$items[$id][0] = (array) $file + array(
'is_default' => TRUE,
'alt' => '',
'title' => '',
);
}
}
}
}
/**
* Implements hook_field_presave().
*/
function my_watermark_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items)
{
file_field_presave($entity_type, $entity, $field, $instance, $langcode, $items);
// Determine the dimensions if necessary.
foreach ($items as &$item)
{
if (!isset($item['width']) || !isset($item['height']))
{
$info = image_get_info(file_load($item['fid'])->uri);
if (is_array($info))
{
$item['width'] = $info['width'];
$item['height'] = $info['height'];
}
}
}
}
/**
* Implements hook_field_insert().
*/
function my_watermark_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items)
{
file_field_insert($entity_type, $entity, $field, $instance, $langcode, $items);
}
/**
* Implements hook_field_update().
*/
function my_watermark_field_update($entity_type, $entity, $field, $instance, $langcode, &$items)
{
file_field_update($entity_type, $entity, $field, $instance, $langcode, $items);
}
/**
* Implements hook_field_delete().
*/
function my_watermark_field_delete($entity_type, $entity, $field, $instance, $langcode, &$items)
{
file_field_delete($entity_type, $entity, $field, $instance, $langcode, $items);
}
/**
* Implements hook_field_delete_revision().
*/
function my_watermark_field_delete_revision($entity_type, $entity, $field, $instance, $langcode, &$items)
{
file_field_delete_revision($entity_type, $entity, $field, $instance, $langcode, $items);
}
/**
* Implements hook_field_is_empty().
*/
function my_watermark_field_is_empty($item, $field)
{
return file_field_is_empty($item, $field);
}