Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm new to Drupal but have been given the task of creating a widget.
The module loads, fields are displayed, but when I create some content the form values are not being stored when the content is being saved.
.install file:
function cloudinary_field_schema($field) {
$columns = array(
'publicID' => array('type' => 'varchar', 'length' => 255, 'not null' => FALSE),
'url' => array('type' => 'varchar', 'length' => 255, 'not null' => FALSE),
'caption' => array('type' => 'varchar', 'length' => 255, 'not null' => FALSE),
'alt' => array('type' => 'varchar', 'length' => 255, 'not null' => FALSE),
'credit' => array('type' => 'varchar', 'length' => 255, 'not null' => FALSE)
);
return array(
'columns' => $columns,
'indexes' => array(),
);
}
.module file:
/**
* Implements hook_field_info().
* define the field type
*/
function cloudinary_field_info() {
return array(
'cloudinary' => array(
'label' => t('Cloudinary image selector'),
'description' => t('Search for images and select one for display.'),
'default_widget' => 'cloudinary_widget',
'default_formatter' => 'cloudinary_formatter',
'settings' => array(),
'instance_settings' => array(),
)
);
}
/**
* This is the dropdown options for widget
*/
function cloudinary_field_widget_info() {
return array(
'cloudinary_widget' => array(
'label' => t('Default'),
'field types' => array('cloudinary', 'text'),
'behaviours' => array('multiple values' => 'FIELD_BEHAVIOUR_DEFAULT'),
)
);
}
/**
*/
function cloudinary_field_widget_form(&$form, &$form_state, $field, $instance, $lang, $items, $delta, $element) {
$element += array(
'#type' => 'fieldset',
);
$item =& $items[$delta];
$element['field_cloudinary_publicID'] = array(
'#title' => t('Public ID'),
'#type' => 'textfield',
'#required' => TRUE,
'#default_value' => isset($item['field_cloudinary_publicID']) ? $item['field_cloudinary_publicID'] : '',
);
$element['field_cloudinary_url'] = array(
'#title' => t('Url'),
'#type' => 'textfield',
'#required' => TRUE,
'#default_value' => isset($item['field_cloudinary_url']) ? $item['field_cloudinary_url'] : '',
);
$element['field_cloudinary_caption'] = array(
'#title' => t('Caption'),
'#type' => 'textfield',
'#required' => TRUE,
'#default_value' => isset($item['field_cloudinary_caption']) ? $item['field_cloudinary_caption'] : '',
);
$element['field_cloudinary_alt'] = array(
'#title' => t('Alt'),
'#type' => 'textfield',
'#required' => TRUE,
'#default_value' => isset($item['field_cloudinary_alt']) ? $item['field_cloudinary_alt'] : '',
);
$element['field_cloudinary_credit'] = array(
'#title' => t('Credit'),
'#type' => 'textfield',
'#required' => TRUE,
'#default_value' => isset($item['field_cloudinary_credit']) ? $item['field_cloudinary_credit'] : '',
);
return $element;
}
function cloudinary_field_is_empty($item, $field) {
$flag = FALSE;
foreach ($item as $key => $value) {
if(empty($key[$value])) {
$flag = TRUE;
}
}
return !$flag;
}
function cloudinary_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
foreach ($items as $delta => $item) {
if (!isset($item['field_cloudinary_publicID']) ||
!isset($item['field_cloudinary_url']) ||
!isset($item['field_cloudinary_caption']) ||
!isset($item['field_cloudinary_alt']) ||
!isset($item['field_cloudinary_credit'])) {
$errors[$field['field_name']][$langcode][$delta][] = array(
'error' => 'cloudinary_fields_missing',
'message' => t('%title: Make sure all fields are completed. '.
'Make sure all fiends are entered.',
array('%title' => $instance['label'])
),
);
}
}
}
function cloudinary_field_widget_error($element, $error, $form, &$form_state) {
switch ($error['error']) {
case 'cloudinary_fields_missing':
form_error($element, $error['message']);
break;
}
}
function cloudinary_field_formatter_info() {
return array(
'cloudinary_formatter' => array(
'label' => t('Default'),
'field types' => array('cloudinary'),
),
);
}
function cloudinary_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
foreach ($items as $delta => $item) {
$element[$delta] = cloudinary_format_field($item);
}
return $element;
}
function poutine_maker_format_field($item) {
$element = array(
'#type' => 'container',
'#attributes' => array( 'class' => array( 'field-item') ),
);
$element['field_cloudinary_publicID'] = array(
'label' => array(
'#type' => 'container',
'#attributes' => array( 'class' => array( 'field-label' )),
'text' => array(
'#markup' => t('Public ID'),
),
),
'item' => array(
'#type' => 'container',
'#attributes' => array( 'class' => array( 'field-item') ),
'text' => array(
'#markup' => $item['field_cloudinary_publicID'],
),
),
);
$element['field_cloudinary_url'] = array(
'label' => array(
'#type' => 'container',
'#attributes' => array( 'class' => array( 'field-label' )),
'text' => array(
'#markup' => t('Image Url'),
),
),
'item' => array(
'#type' => 'container',
'#attributes' => array( 'class' => array( 'field-item') ),
'text' => array(
'#markup' => $item['field_cloudinary_url'],
),
),
);
$element['field_cloudinary_caption'] = array(
'label' => array(
'#type' => 'container',
'#attributes' => array( 'class' => array( 'field-label' )),
'text' => array(
'#markup' => t('Image Caption'),
),
),
'item' => array(
'#type' => 'container',
'#attributes' => array( 'class' => array( 'field-item') ),
'text' => array(
'#markup' => $item['field_cloudinary_caption'],
),
),
);
$element['field_cloudinary_alt'] = array(
'label' => array(
'#type' => 'container',
'#attributes' => array( 'class' => array( 'field-label' )),
'text' => array(
'#markup' => t('Image Alt'),
),
),
'item' => array(
'#type' => 'container',
'#attributes' => array( 'class' => array( 'field-item') ),
'text' => array(
'#markup' => $item['field_cloudinary_alt'],
),
),
);
$element['field_cloudinary_credit'] = array(
'label' => array(
'#type' => 'container',
'#attributes' => array( 'class' => array( 'field-label' )),
'text' => array(
'#markup' => t('Image Credit'),
),
),
'item' => array(
'#type' => 'container',
'#attributes' => array( 'class' => array( 'field-item') ),
'text' => array(
'#markup' => $item['field_cloudinary_credit'],
),
),
);
return $element;
}
function cloudinary_format_canvas_field($item) {
drupal_add_js(drupal_get_path('module', 'cloudinary') . '/cloudinary.js');
}
You need to implement hook_field_schema in your .install file.
// Something like this
function cloudinary_field_schema($field) {
// $field['type']
return array(
'columns' => array(
'column_name' => array(
'type' => 'float',
'size' => 'big',
'not null' => TRUE,
'default' => 0,
),
)
);
}
It was a logic problem in cloudinary_field_is_empty(). It was always returning false. All working fine now! Thanks for your help Zolyboy!
Related
I created my module and in the creation of a ListForm I added the "Position" column as seen in the Prestashop Doc but I don't have the arrows appearing to drag and drop nor the possibility to drag and drop. Prestashop 1.7
if ($result = Db::getInstance()->executeS($sql)) {
//Les champs à afficher
$this->_defaultOrderBy = 'position';
$this->fields_list = array(
'id_slider' => array(
'title' => 'ID',
'width' => 'auto',
'type' => 'text'
),
'commentaire' => array(
'title' => $this->l('commentaire'),
'width' => 'auto',
'type' => 'text'
),
'link' => array(
'title' => $this->l('link'),
'width' => 'auto',
'type' => 'text'
),
'test' => array(
'title' => $this->l('active'),
'active' => 'test',
'width' => 'auto',
'type' => 'bool',
'ajax' => true,
'align' => 'center'
),
'position' => array(
'title' => $this->l('Ordem'),
'filter_key' => 'a!position',
'position' => 'position',
'align' => 'center',
'class' => 'fixed-width-md'
),
'image' => array(
'title' => $this->l('image/video'),
'width' => 'auto',
'type' => 'text'
),
'videocover' => array(
'title' => $this->l('image/video'),
'width' => 'auto',
'type' => 'text'
),
'imagemobile' => array(
'title' => $this->l('image/video'),
'width' => 'auto',
'type' => 'text'
),
'imagepng' => array(
'title' => $this->l('image/png'),
'width' => 'auto',
'type' => 'text'
),
'imagepngmobile' => array(
'title' => $this->l('image/png'),
'width' => 'auto',
'type' => 'text'
)
);
$helper = new HelperList();
$helper->shopLinkType = '';
$helper->simple_header = false;
$helper->identifier = 'id_slider';
$helper->actions = array('edit', 'delete');
$helper->show_toolbar = true;
$helper->title = $this->displayName;
$helper->table = $this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
$helper->toolbar_btn['new'] = array(
'href' => AdminController::$currentIndex.'&configure='.$this->name.'&new='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules'),
'desc' => $this->l('Nouveau slider')
);
return $helper->generateList($result, $this->fields_list);
}
return false;
}
I put you the image of an example found with what I expect and what I have.
I wish to have els felches on the side
You need to add this :
$helper->position_identifier = 'position';
$helper->orderBy = 'position';
$helper->orderWay = 'asc';
I am working on a theme for my customer and facing a problem with a module of WP bakery and the module is created by the theme owners.
Here is the code where I am facing the problem:
use MikadoCore\Lib;
class PricingItem implements Lib\ShortcodeInterface {
private $base;
function __construct() {
$this->base = 'mkd_pricing_item';
add_action('vc_before_init', array($this, 'vcMap'));
}
public function getBase() {
return $this->base;
}
public function vcMap() {
vc_map( array(
'name' => esc_html__('Mikado Pricing Item', 'mkd-core'),
'base' => $this->base,
'icon' => 'icon-wpb-pricing-item extended-custom-icon',
'category' => esc_html__('by MIKADO', 'mkd-core'),
'allowed_container_element' => 'vc_row',
'params' => array(
array(
'type' => 'textfield',
'param_name' => 'price_value',
'heading' => esc_html__('Value', 'mkd-core')
),
array(
'type' => 'colorpicker',
'param_name' => 'price_color',
'heading' => esc_html__('Price Color', 'mkd-core'),
'dependency' => array('element' => 'price_value', 'not_empty' => true)
),
array(
'type' => 'textfield',
'param_name' => 'currency',
'heading' => esc_html__('Currency', 'mkd-core'),
'description' => esc_html__('Default mark is $', 'mkd-core')
),
array(
'type' => 'colorpicker',
'param_name' => 'currency_color',
'heading' => esc_html__('Currency Color', 'mkd-core'),
'dependency' => array('element' => 'currency', 'not_empty' => true)
),
array(
'type' => 'textfield',
'param_name' => 'title',
'heading' => esc_html__('Title', 'mkd-core'),
'save_always' => true
),
array(
'type' => 'textfield',
'param_name' => 'subtitle',
'heading' => esc_html__('Subtitle', 'mkd-core')
),
array(
'type' => 'textarea_html',
'param_name' => 'content',
'heading' => esc_html__('Content', 'mkd-core'),
'value' => '<li>content content content</li><li>content content content</li><li>content content content</li>'
)
)
));
}
public function render($atts, $content = null) {
$args = array(
'price_value' => '100',
'price_color' => '',
'currency' => '$',
'currency_color' => '',
'title' => '',
'subtitle' => ''
);
$params = shortcode_atts($args, $atts);
extract($params);
$html = '';
$params['content']= preg_replace('#^<\/p>|<p>$#', '', $content); // delete p tag before and after content
$params['price_styles'] = $this->getPriceStyles($params);
$params['currency_styles'] = $this->getCurrencyStyles($params);
$html .= mkd_core_get_shortcode_module_template_part('templates/pricing-item-template', 'pricing-item', '', $params);
return $html;
}
private function getPriceStyles($params) {
$itemStyle = array();
if (!empty($params['price_color'])) {
$itemStyle[] = 'color: '.$params['price_color'];
}
return implode(';', $itemStyle);
}
private function getCurrencyStyles($params) {
$itemStyle = array();
if (!empty($params['currency_color'])) {
$itemStyle[] = 'color: '.$params['currency_color'];
}
return implode(';', $itemStyle);
}
}
And the result of this code is:
As you can see, price is showing too big that it is covering the text.
How can I reduce the size of the price?
I am working over prestashop admin and i am not able to change the row headers iin products . kindly provide me appropriate solution for the same. Language and Database using is PHP-Mysql
everything you need to change the product page headers you find :
controllers/admin/AdminProductsController.php
in the __construct() function you will find.
for the content:
$this->_select .= 'shop.`name` AS `shopname`, a.`id_shop_default`, ';
$this->_select .= $alias_image.'.`id_image` AS `id_image`, cl.`name` AS `name_category`, '.$alias.'.`price`, 0 AS `price_final`, a.`is_virtual`, pd.`nb_downloadable`, sav.`quantity` AS `sav_quantity`, '.$alias.'.`active`, IF(sav.`quantity`<=0, 1, 0) AS `badge_danger`';
for the header:
$this->fields_list = array();
$this->fields_list['id_product'] = array(
'title' => $this->l('ID'),
'align' => 'center',
'class' => 'fixed-width-xs',
'type' => 'int'
);
$this->fields_list['image'] = array(
'title' => $this->l('Image'),
'align' => 'center',
'image' => 'p',
'orderby' => false,
'filter' => false,
'search' => false
);
$this->fields_list['name'] = array(
'title' => $this->l('Name'),
'filter_key' => 'b!name'
);
$this->fields_list['reference'] = array(
'title' => $this->l('Reference'),
'align' => 'left',
);
if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_SHOP) {
$this->fields_list['shopname'] = array(
'title' => $this->l('Default shop'),
'filter_key' => 'shop!name',
);
} else {
$this->fields_list['name_category'] = array(
'title' => $this->l('Category'),
'filter_key' => 'cl!name',
);
}
$this->fields_list['price'] = array(
'title' => $this->l('Base price'),
'type' => 'price',
'align' => 'text-right',
'filter_key' => 'a!price'
);
$this->fields_list['price_final'] = array(
'title' => $this->l('Final price'),
'type' => 'price',
'align' => 'text-right',
'havingFilter' => true,
'orderby' => false,
'search' => false
);
if (Configuration::get('PS_STOCK_MANAGEMENT')) {
$this->fields_list['sav_quantity'] = array(
'title' => $this->l('Quantity'),
'type' => 'int',
'align' => 'text-right',
'filter_key' => 'sav!quantity',
'orderby' => true,
'badge_danger' => true,
//'hint' => $this->l('This is the quantity available in the current shop/group.'),
);
}
$this->fields_list['active'] = array(
'title' => $this->l('Status'),
'active' => 'status',
'filter_key' => $alias.'!active',
'align' => 'text-center',
'type' => 'bool',
'class' => 'fixed-width-sm',
'orderby' => false
);
of course it is best practice reproduce the override files in:
controllers/admin/AdminProductsController.php
I have multiple arrays:
$meta_boxes[] = array(
'id' => 'measurements',
'title' => 'Measurements',
'fields' => array(
array(
'name' => 'Length',
'id' => 'length',
'type' => 'text',
'std' => ''
),
array(
'name' => 'Manufacturer Length',
'id' => 'manufacturer_length',
'type' => 'text',
'std' => ''
)
)
);
$meta_boxes[] = array(
'id' => 'colors',
'title' => 'Colors',
'fields' => array(
array(
'name' => 'exterior',
'id' => 'exterior',
'type' => 'text',
'std' => ''
etc...
How can I get for example, the value of the name element from fields array from $meta_boxes[] array with id = measurements?
Try something like this:
foreach ($meta_boxes as $meta_box) {
if($meta_box['id'] !== 'measurements') {
continue;
}
$output = $meta_box['fields'];
break;
}
i have created a module with this among others this function in it:
<?php
function ils_ladda_upp_form() {
$form['upload'] = array(
'#method' => 'post',
'#attributes' => array(
'enctype' => 'multipart/form-data',
)
);
$form['upload']['album_name'] = array(
'#type' => 'textfield',
'#title' => t('Albumnamn'),
'#required' => 1
);
$form['upload']['album_location'] = array(
'#type' => 'textfield',
'#title' => t('Plats'),
);
$form['upload']['album_date'] = array(
'#type' => 'date',
'#title' => t('Datum'),
'#required' => 1,
'#suffix' => '(då bilderna togs)'
);
$form['upload']['album_description'] = array(
'#type' => 'textarea',
'#title' => t('Beskrivning'),
'#resizable' => false,
);
$form['upload']['school'] = array(
'#type' => 'hierarchical_select',
'#title' => t('Skola & Klass'),
'#size' => 1,
'#required' => 1,
'#config' => array(
'module' => 'hs_taxonomy',
'params' => array(
'vid' => 1,
),
'save_lineage' => 0,
'enforce_deepest' => 0,
'entity_count' => 0,
'require_entity' => 0,
'resizable' => 0,
'level_labels' => array(
'status' => 0,
'labels' => array(
0 => t('Main category'),
1 => t('Subcategory'),
2 => t('Third level category'),
),
),
'dropbox' => array(
'status' => 0,
'title' => t('All selections'),
'limit' => 0,
'reset_hs' => 1,
),
'editability' => array(
'status' => 0,
'item_types' => array(),
'allowed_levels' => array(
0 => 0,
1 => 0,
2 => 1,
),
'allow_new_levels' => 0,
'max_levels' => 3,
),
# These settings cannot be configured through the UI: they can only be
# overridden through code.
'animation_delay' => 400,
'special_items' => array(),
'render_flat_select' => 0,
'path' => 'hierarchical_select_json',
),
#'#default_value' => '83',
);
$form['upload']['file'] = array(
'#type' => 'file',
'#title' => t('Bild'),
);
$form['upload']['name'] = array(
'#type' => 'textfield',
'#required' => true,
'#title' => t('Ditt namn')
);
$form['upload']['submit'] = array('#type' => 'submit', '#value' => t('Ladda upp'));
return $form['upload'];
}
?>
Is it possible to insert a CCK Filefield/imagefield in the form? If so, how do i do it?
Drupal v. 6.15
Regards,
Joar
Like this? http://sysadminsjourney.com/content/2010/01/26/display-cck-filefield-or-imagefield-upload-widget-your-own-custom-form
You should use:
D6: http://drupal.org/project/upload_element
upload_element type
D7: managed_file type
Instead of CCK filefield, it is almost the same (ajax, ahah upload) & you can implement it without hacking CCK