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
Related
After I included ACF into my Plugin fields of type 'user' and 'post_object' don't work any more. They worked perfectly fine before I included ACF. They are displayed but they don't show me any options any more. Any clue what this might have caused? I guess that some link might have changed but I can't find any hint to that in the code:
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array(
'key' => 'group_5f65057cd8301',
'title' => 'Employees Details',
'fields' => array(
array(
'key' => 'field_5f8a0c6792e45',
'label' => 'Display Name',
'name' => 'display_name',
'type' => 'user',
'instructions' => '',
'required' => 1,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'role' => array(
0 => 'employee',
1 => 'administrator',
),
'allow_null' => 0,
'multiple' => 0,
'return_format' => 'array',
),
array(
'key' => 'field_5f65089dbbe1d',
'label' => 'Occupation',
'name' => 'occupation',
'type' => 'post_object',
'instructions' => '',
'required' => 1,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'post_type' => array(
0 => 'occupations',
),
'taxonomy' => '',
'allow_null' => 0,
'multiple' => 0,
'return_format' => 'object',
'ui' => 1,
),
array(
'key' => 'field_5f8b42ca6c4c6',
'label' => 'Costs per Hour',
'name' => 'costs_per_hour',
'type' => 'number',
'instructions' => 'Enter a number with max 2 decimals, separated by ".", e.g. "35.46"',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'min' => '',
'max' => '',
'step' => '0.01',
),
),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'employees',
),
),
),
'menu_order' => 0,
'position' => 'acf_after_title',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => true,
'description' => '',
));
endif;
In the meantime I found this:
In the console there are errors as these:
Failed to load resource: the server responded .../advanced-custom-fields/assets/css/acf-global.css?ver=5.9.1
ReferenceError:Can't find variable: acf Global Code post-new.php 1972
(actually my post-new.php doesn't even have so many lines)
When I click on the last one the debugger gives me this:
acf.data = {"postboxes":[{...
acf.doAction( 'prepare' )
And when I finally look into the apache_error.log there are errors like:
File does not exist: /Applications/MAMP/htdocs/myPlugin/Applications, referrer: http://localhost:8888/myPlugin/wp-admin/post-new.php?post_type=jobs
On my WordPress website I have the ACF plugin installed and I'm using the fields on several pages in the 'regular' way. So I created the groups and fields in the backend. Everything works fine.
Now I want to generate php code of a couple of those field groups (because I want to change the code slightly). Where do I put the code and what’s the best way to do this?
I've created a new php file acf-deals.php and uploaded it to the /php-includes/ directory in the root directory. It includes the following code:
<?php
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array(
'key' => 'group_deal1',
'title' => 'Deal One (displayed on homepage)',
'fields' => array(
array(
'key' => 'field_5c66e017f8359',
'label' => 'Title',
'name' => 'deal_title_one',
'type' => 'text',
'instructions' => '(max. 100 characters)',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => 'deals-title',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => 100,
),
array(
'key' => 'field_5c6d43781bcb1',
'label' => 'Deal or Discount',
'name' => 'discount_deal_or_special_one',
'type' => 'radio',
'instructions' => '',
'required' => 0,
'conditional_logic' => array(
array(
array(
'field' => 'field_5c66e017f8359',
'operator' => '!=empty',
),
),
),
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'choices' => array(
'Discount' => 'Discount',
'Deal' => 'Deal',
),
'allow_null' => 1,
'other_choice' => 0,
'default_value' => '',
'layout' => 'vertical',
'return_format' => 'value',
'save_other_choice' => 0,
),
array(
'key' => 'field_5c66e094f835a',
'label' => 'Description',
'name' => 'deal_description_one',
'type' => 'textarea',
'instructions' => '(max. 600 characters)',
'required' => 0,
'conditional_logic' => array(
array(
array(
'field' => 'field_5c66e017f8359',
'operator' => '==empty',
),
),
),
'wrapper' => array(
'width' => '',
'class' => 'deals-description',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'maxlength' => 600,
'rows' => '',
'new_lines' => '',
),
array(
'key' => 'field_5c66e0d4f835b',
'label' => 'Regular price',
'name' => 'regular_price_one',
'type' => 'number',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => 'deals-regular-price',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '$',
'append' => '',
'min' => '',
'max' => '',
'step' => '',
),
array(
'key' => 'field_5c66e130f835c',
'label' => 'Discounted price / deal price',
'name' => 'discounted_price_one',
'type' => 'number',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => 'deals-discounted-price',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '$',
'append' => '',
'min' => '',
'max' => '',
'step' => '',
),
array(
'key' => 'field_5c703c1fd5851',
'label' => 'Valid until',
'name' => 'valid_until_one',
'type' => 'date_picker',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'display_format' => 'm/d/Y',
'return_format' => 'm/d/Y',
'first_day' => 1,
),
),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'post',
),
array(
'param' => 'post_format',
'operator' => '==',
'value' => 'aside',
),
),
array(
array(
'param' => 'post_format',
'operator' => '==',
'value' => 'status',
),
),
),
'menu_order' => 1,
'position' => 'acf_after_title',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => 1,
'description' => '',
));
endif;
?>
I've added this code to my single-aside.php file:
<?php get_template_part( '/php-includes/acf-deals.php', 'acf-deals' ); ?>
Unfortunately the field are not showing up in the WP admin backend. What am I doing wrong? I searched and searched but can't find a proper explanation or a way to fix it. I hope someone can help.
Thanks for your help!
add_action('acf/init', function(){
... add local fields
})
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
Im using Editable Grid extension of CGridview.
MY Grid:
$this->widget('EditableGrid', array(
'dataProvider' => $dataProvider,
'template' => '{items}{pager} ',
'id' => 'PO-grid',
'htmlOptions'=>array(
//'style'=>'width:1100px;'
),
'columns' => array(
array(
'class' => 'EditableGridColumn',
'header' => '',
'name' => 'PO_{gridNum}_{rowNum}_edit',
'imageurl'=> Yii::app()->request->baseUrl.'/images/update.png',
'tag' => 'button',
'tagHtmlOptions' => array(
)
),
array(
'class' => 'EditableGridColumn',
'header' => 'StentysRef',
'name' => '[{gridNum}][{rowNum}]ref',
'tag' => 'textField',
'tagHtmlOptions' => array(
'readonly'=>true
)
),
array(
'class' => 'EditableGridColumn',
'header' => 'SupplierRef',
'name' => '[{gridNum}][{rowNum}]productref',
'tag' => 'textField',
'tagHtmlOptions' => array(
'readonly'=>true
)
),
array(
'class' => 'EditableGridColumn',
'header' => 'Product',
'name' => '[{gridNum}][{rowNum}]productname',
'tag' => 'textField',
'tagHtmlOptions' => array(
// 'size' => '2'
'readonly'=>true
)
),
array(
'class' => 'EditableGridColumn',
'header' => 'Qty',
'name' => '[{gridNum}][{rowNum}]qty',
'tag' => 'textField',
'tagHtmlOptions' => array(
'size' => '2',
'readonly'=>true,'width'=>'10px','style'=>'width:70px;'
)
),
array(
'class' => 'EditableGridColumn',
'header' => 'Description',
'name' => '[{gridNum}][{rowNum}]description',
'tag' => 'textField',
'tagHtmlOptions' => array(
// 'size' => '5'
'readonly'=>true
)
),
array('class'=>'CButtonColumn','template' => '{delete}',
'buttons'=>array(
'delete' => array(
'options'=>array('style'=>'margin-left:20px'),
'imageUrl'=>\Yii::app()->request->baseUrl.'/images/delete.png', )
),
),
),
));?>
My problem is, Gridview is fit with 1600 X 900 px screen , it should not fit with below px.
Anyone please help me to reolve this problem.
I want to make this grid fit with screen 1366 px.
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!