$style='<style>#page *{
margin-top: 0cm;
margin-bottom: 0cm;
margin-left: 0cm;
margin-right: 0cm;
}</style>';
$html ='<img src="temppng/'.$_GET['memid'].'.png" width="325.03937" height="204.094488" `/>';
include("MPDF54/mpdf.php");
$mpdf = new mPDF('utf-8', 'Letter', 0, '', 1, 1, 1, 1, 8, 8);
$mpdf->useAdobeCJK = true;
$mpdf->SetAutoFont(AUTOFONT_ALL);
`$mpdf->SetMargins(0);
$mpdf->WriteHTML('<pagebreak sheet-size="86mm 54mm" />');
$mpdf->WriteHTML($style);
$mpdf->WriteHTML($html);
$mpdf->WriteHTML('<tocentry content="150mm square" />')
$mpdf->DeletePages(1,1);
$mpdf->Output();
Hi,any one know how to delete the bottom white space of the pdf,here is image 'http://tinypic.com/view.php?pic=xfdixj&s=8',i want to delete the bottom white space,any one know
how to do?THX
Create it with 0 margins or whatever you'd like accordingly
$mpdf=new mPDF('utf-8', 'Letter', 0, '', 0, 0, 0, 0, 0, 0);
class mPDF ([ string $mode [, mixed $format [, float $default_font_size [, string $default_font [, float $margin_left , float $margin_right , float $margin_top , float $margin_bottom , float $margin_header , float $margin_footer [, string $orientation ]]]]]])
mpdf page layout can be customize with the following approach
For mpdf version 6.0 we can use
$mpdf=new mPDF('utf-8', 'A4', 0, '', 0, 0, 0, 0, 0, 'L'); // use this customization
The default settings of mPDf in version 6.0 along with the parameters looks like
function mPDF($mode='',$format='A4',$default_font_size=0,$default_font='',$mgl=15,$mgr=15,$mgt=16,$mgb=16,$mgh=9,$mgf=9, $orientation='P')
For mpdf version 7.0 or greater we can use
$mpdf= new \Mpdf\Mpdf(['mode' => 'utf-8','format' => 'A4','margin_left' => 0,'margin_right' => 0,'margin_top' => 0,'margin_bottom' => 0,'margin_header' => 0,'margin_footer' => 0]); //use this customization
The default settings of mPDf in version 7.0 along with the parameters looks like
$constructor = [
'mode' => '',
'format' => 'A4',
'default_font_size' => 0,
'default_font' => '',
'margin_left' => 15,
'margin_right' => 15,
'margin_top' => 16,
'margin_bottom' => 16,
'margin_header' => 9,
'margin_footer' => 9,
'orientation' => 'P',
];
Futher detail regarding the available options of mPDF class can be get from the official documentaion https://mpdf.github.io/reference/mpdf-functions/construct.html
You can adjust the margins using by setting parameters as below
new Pdf([
'mode' => '', // leaner size using standard fonts
'format' => Pdf::FORMAT_A4,
'orientation' => Pdf::ORIENT_LANDSCAPE,
'marginTop' => 0,
'marginBottom' => 0,
'marginLeft' => 0,
'marginRight' => 0,
'destination' => Pdf::DEST_BROWSER,
'content' => $this->renderPartial('certificate_pdf', ['']),
'options' => [
// any mpdf options you wish to set
],
'methods' => [
'SetTitle' => '',
'SetSubject' => '',
'SetHeader' => [''],
'SetFooter' => [''],
'SetAuthor' => 'Ajira Tracking',
'SetCreator' => 'Ajira Tracking',
'SetKeywords' => 'Ajira Tracking',
]
]);
Related
Drupal does not allow me to delete extension (recurring_commerce) as some fields needs to be deleted manually. This issue is described in detalis below.
Solution is to add some code to a file as described in #11 of the issue below.
Basically I need to programmatically delete a field and I have never done it before. Writing kind of a hook (?).
I tried to paste the suggested code before, after the original code as well as replacing the original code with a suggested one.
Every time after changing the code I am restarting the server, running cron and clear cache.
Still I am unable to uninstall the exension from drupal as I have the following message:
The following reason prevents Commerce Recurring from being uninstalled:
The Billing period field type is used in the following fields: commerce_order.billing_period, commerce_order_item.billing_period
Details of the following issue:
please skip to #11
https://www.drupal.org/project/commerce_recurring/issues/2924965
Suggested code to apply:
function commerce_recurring_update_8101(&$sandbox) {
\Drupal::entityManager()->getStorage('field_config')->load('commerce_order.recurring.billing_period')->delete();
\Drupal::entityManager()->getStorage('field_config')->load('commerce_order.recurring.billing_schedule')->delete();
\Drupal::entityManager()->getStorage('field_config')->load('commerce_order.recurring.order_items')->delete();
\Drupal::entityManager()->getStorage('field_config')->load('commerce_order_item.recurring_standalone.billing_period')->delete();
\Drupal::entityManager()->getStorage('field_config')->load('commerce_order_item.recurring_standalone.subscription')->delete();
\Drupal::entityManager()->getStorage('field_config')->load('commerce_order_item.recurring_product_variation.billing_period')->delete();
\Drupal::entityManager()->getStorage('field_config')->load('commerce_order_item.recurring_product_variation.subscription')->delete();
}
function commerce_recurring_update_8102(&$sandbox) {
\Drupal::entityTypeManager()->getStorage('commerce_order_type')->load('recurring')->delete();
\Drupal::entityTypeManager()->getStorage('commerce_order_item_type')->load('recurring_standalone')->delete();
\Drupal::entityTypeManager()->getStorage('commerce_order_item_type')->load('recurring_product_variation')->delete();
}
Original code in my file:
/**
* Add the 'trial_starts' and "trial_ends" fields to subscriptions.
*/
function commerce_recurring_update_8101(&$sandbox) {
$fields = [];
$fields['trial_starts'] = BaseFieldDefinition::create('timestamp')
->setLabel(t('Trial starts'))
->setDescription(t('The time when the subscription trial starts.'))
->setRequired(FALSE)
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'timestamp',
'weight' => 0,
])
->setDisplayOptions('form', [
'type' => 'datetime_timestamp',
'weight' => 0,
])
->setDisplayConfigurable('form', TRUE);
$fields['trial_ends'] = BaseFieldDefinition::create('timestamp')
->setLabel(t('Trial ends'))
->setDescription(t('The time when the subscription trial ends.'))
->setRequired(FALSE)
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'timestamp',
'weight' => 0,
])
->setDisplayOptions('form', [
'type' => 'datetime_timestamp',
'weight' => 0,
])
->setDisplayOptions('form', [
'type' => 'datetime_timestamp',
'weight' => 0,
])
->setDisplayConfigurable('form', TRUE);
$update_manager = \Drupal::entityDefinitionUpdateManager();
foreach ($fields as $name => $storage_definition) {
$update_manager->installFieldStorageDefinition($name, 'commerce_subscription', 'commerce_recurring', $storage_definition);
}
}
/**
* Make the billing_schedule field required on subscriptions.
*/
function commerce_recurring_update_8102() {
$entity_definition_update = \Drupal::entityDefinitionUpdateManager();
$field_definition = $entity_definition_update->getFieldStorageDefinition('billing_schedule', 'commerce_subscription');
$field_definition->setRequired(TRUE);
$entity_definition_update->updateFieldStorageDefinition($field_definition);
}
This post has some solution, but author wants to improve it
Having read a lot of documentations and forums I couldn't find perfect solution for my problem. I want to use tinyMCE in theme option in admin panel for some reason. I added tiny to page and it shows well, but when I submit - it doesn't save anything. Of course I checked veriables and recognized that no new data was submitted. So, I made up solution simply to copy data from tinyMCE to hidden field and then that hidden field store to database.
Here some code:
theme-options.php
<?php wp_editor($options['king_text1'], 'kingtext', array(
'wpautop' => 1,
'media_buttons' => 1,
'textarea_name' => '',
'textarea_rows' => 20,
'tabindex' => null,
'editor_css' => '',
'editor_class' => 'tiny_kingtext',
'teeny' => 0,
'dfw' => 0,
'tinymce' => 1,
'quicktags' => 1,
'drag_drop_upload' => false
) ); ?>
<textarea id="kingtext" class="large-text" cols="50" rows="10"><?php echo esc_attr_e( $options['king_text1'] ); ?> </textarea>
<input type="hidden" id="myText" name="king_theme_options[king_text1]">
Then I added function of adding custom script to admin panel in head of theme-option file:
function javascript_and_styles() {
wp_enqueue_script( 'admin-js', get_template_directory_uri() . '/js/admin-panel.js', array(), '', true );
}
add_action('admin_enqueue_scripts', 'javascript_and_styles');
And after that I added some script which copies data from mce to hidden input before submit:
jQuery(function() {
jQuery('input.button').click(function(e) {
e.preventDefault();
var content = tinyMCE.activeEditor.getContent();
jQuery('#myText').val(content);
jQuery('#myform').submit();
});
});
After this everything works, but I don’t like this code and this method of solving the problem. If someone knows more interesting solution, show it.
Best regards
I have just found all my mistakes. This question is solved!
It is very important to understand clearly each property in wp_editor. My problem was that I used both textarea and wp_editor, that is why I had troubles which I had described above. So, if someone has the same situation as me, I would like to get you this recommndation:
You mustn't use real textarea in your code. You start wp_editor like this:
<?php wp_editor($options['king_text1'], 'kingtext', array(
'wpautop' => 1,
'media_buttons' => 1,
'textarea_name' => 'king_theme_options[king_text1]', //This is important line!!!
'textarea_rows' => 20,
'tabindex' => null,
'editor_css' => '',
'editor_class' => 'tiny_kingtext',
'teeny' => 0,
'dfw' => 0,
'tinymce' => 1,
'quicktags' => 1,
'drag_drop_upload' => false
) );
After all no other thicks are neccessary. Everything works well: opens, saves etc.
How to set border color of a cell?
I used this code, but it's not working:
$objPHPExcel->getActiveSheet()
->getStyle('A1')
->getBorders()
->getAllBorders()
->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN)
->getColor()
->setRGB('DDDDDD');
I know applyFromArray() works fine. But I don't want to use it.
A bit late, but for the record, I found that this syntax worked fine;
$ActiveSheet->getStyle("A1:Z1")->applyFromArray(
array(
'borders' => array(
'allborders' => array(
'style' => PHPExcel_Style_Border::BORDER_THIN,
'color' => array('rgb' => 'DDDDDD')
)
)
)
);
I also found a complete list of styles and attributes here: http://www.bainweb.com/2012/01/phpexcel-style-reference-complete-list.html
You can apply color to cells border while creating border.
Define style :
$border_style= array('borders' => array('right' => array('style' =>
PHPExcel_Style_Border::BORDER_THICK,'color' => array('argb' => '766f6e'),)));
Apply style :
$sheet = $objPHPExcel->getActiveSheet();
$sheet->getStyle("A2:A40")->applyFromArray($border_style);
Refer PhpExcel documentation here
Set border without applyFromArray() can be done like this.
$objPHPExcel->getActiveSheet()
->getStyle('A1')
->getBorders()
->getBottom()
->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$objPHPExcel->getActiveSheet()
->getStyle('A1')
-> getBorders()
->getLeft()
->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$objPHPExcel->getActiveSheet()
->getStyle('A1')
->getBorders()
->getRight()
->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$objPHPExcel->getActiveSheet()
->getStyle('A1')
->getBorders()
->getBottom()
->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
The Border Style list are
BORDER_NONE - 'none'
BORDER_DASHDOT - 'dashDot'
BORDER_DASHDOTDOT - 'dashDotDot'
BORDER_DASHED - 'dashed'
BORDER_DOTTED - 'dotted'
BORDER_DOUBLE - 'double'
BORDER_HAIR - 'hair'
BORDER_MEDIUM - 'medium'
BORDER_MEDIUMDASHDOT - 'mediumDashDot'
BORDER_MEDIUMDASHDOTDOT - 'mediumDashDotDot'
BORDER_MEDIUMDASHED - 'mediumDashed'
BORDER_SLANTDASHDOT - 'slantDashDot'
BORDER_THICK - 'thick'
BORDER_THIN - 'thin'
For more PHPExcel
Website is down so here is complete list of PHPExcel styles:
/* PHPExcel Object */
/* Get the default Style object */
(PHPExcel_Style) $style = ((PHPExcel) $excel)->getDefaultStyle()
/* PHPExcel_Cell Object */
/* Get the Style object for a Cell */
(PHPExcel_Style) $style = ((PHPExcel) $excel)->getStyle('A1')
/* Styles */
/* Apply new Style from array */
$style->applyFromArray(
array(
'alignment' => array(
'horizontal' =>
PHPExcel_Style_Alignment::HORIZONTAL_GENERAL = 'general'
PHPExcel_Style_Alignment::HORIZONTAL_LEFT = 'left'
PHPExcel_Style_Alignment::HORIZONTAL_RIGHT = 'right'
PHPExcel_Style_Alignment::HORIZONTAL_CENTER = 'center'
PHPExcel_Style_Alignment::HORIZONTAL_CENTER_CONTINUOUS = 'centerContinuous'
PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY = 'justify'
'vertical' =>
PHPExcel_Style_Alignment::VERTICAL_BOTTOM = 'bottom'
PHPExcel_Style_Alignment::VERTICAL_TOP = 'top'
PHPExcel_Style_Alignment::VERTICAL_CENTER = 'center'
PHPExcel_Style_Alignment::VERTICAL_JUSTIFY = 'justify'
'rotation' => (int)
'wrap' => (boolean)
'shrinkToFit' => (boolean)
'indent' => (int)
)
'borders' => array(
'allborders' => array(
'style' =>
PHPExcel_Style_Border::BORDER_NONE = 'none';
PHPExcel_Style_Border::BORDER_DASHDOT = 'dashDot';
PHPExcel_Style_Border::BORDER_DASHDOTDOT = 'dashDotDot';
PHPExcel_Style_Border::BORDER_DASHED = 'dashed';
PHPExcel_Style_Border::BORDER_DOTTED = 'dotted';
PHPExcel_Style_Border::BORDER_DOUBLE = 'double';
PHPExcel_Style_Border::BORDER_HAIR = 'hair';
PHPExcel_Style_Border::BORDER_MEDIUM = 'medium';
PHPExcel_Style_Border::BORDER_MEDIUMDASHDOT = 'mediumDashDot';
PHPExcel_Style_Border::BORDER_MEDIUMDASHDOTDOT = 'mediumDashDotDot';
PHPExcel_Style_Border::BORDER_MEDIUMDASHED = 'mediumDashed';
PHPExcel_Style_Border::BORDER_SLANTDASHDOT = 'slantDashDot';
PHPExcel_Style_Border::BORDER_THICK = 'thick';
PHPExcel_Style_Border::BORDER_THIN = 'thin';
'color' => array(
'rgb' =>
PHPExcel_Style_Color::COLOR_BLACK = 'FF000000';
PHPExcel_Style_Color::COLOR_WHITE = 'FFFFFFFF';
PHPExcel_Style_Color::COLOR_RED = 'FFFF0000';
PHPExcel_Style_Color::COLOR_DARKRED = 'FF800000';
PHPExcel_Style_Color::COLOR_BLUE = 'FF0000FF';
PHPExcel_Style_Color::COLOR_DARKBLUE = 'FF000080';
PHPExcel_Style_Color::COLOR_GREEN = 'FF00FF00';
PHPExcel_Style_Color::COLOR_DARKGREEN = 'FF008000';
PHPExcel_Style_Color::COLOR_YELLOW = 'FFFFFF00';
PHPExcel_Style_Color::COLOR_DARKYELLOW = 'FF808000';
)
)
'left' => // See 'allborders'
'top' => // See 'allborders'
'right' => // See 'allborders'
'bottom' => // See 'allborders'
'diagonal' =>
'diagonaldirection' =>
)
'fill' => array(
'type' =>
PHPExcel_Style_Fill::FILL_NONE = 'none';
PHPExcel_Style_Fill::FILL_SOLID = 'solid';
PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR = 'linear';
PHPExcel_Style_Fill::FILL_GRADIENT_PATH = 'path';
PHPExcel_Style_Fill::FILL_PATTERN_DARKDOWN = 'darkDown';
PHPExcel_Style_Fill::FILL_PATTERN_DARKGRAY = 'darkGray';
PHPExcel_Style_Fill::FILL_PATTERN_DARKGRID = 'darkGrid';
PHPExcel_Style_Fill::FILL_PATTERN_DARKHORIZONTAL = 'darkHorizontal';
PHPExcel_Style_Fill::FILL_PATTERN_DARKTRELLIS = 'darkTrellis';
PHPExcel_Style_Fill::FILL_PATTERN_DARKUP = 'darkUp';
PHPExcel_Style_Fill::FILL_PATTERN_DARKVERTICAL = 'darkVertical';
PHPExcel_Style_Fill::FILL_PATTERN_GRAY0625 = 'gray0625';
PHPExcel_Style_Fill::FILL_PATTERN_GRAY125 = 'gray125';
PHPExcel_Style_Fill::FILL_PATTERN_LIGHTDOWN = 'lightDown';
PHPExcel_Style_Fill::FILL_PATTERN_LIGHTGRAY = 'lightGray';
PHPExcel_Style_Fill::FILL_PATTERN_LIGHTGRID = 'lightGrid';
PHPExcel_Style_Fill::FILL_PATTERN_LIGHTHORIZONTAL = 'lightHorizontal';
PHPExcel_Style_Fill::FILL_PATTERN_LIGHTTRELLIS = 'lightTrellis';
PHPExcel_Style_Fill::FILL_PATTERN_LIGHTUP = 'lightUp';
PHPExcel_Style_Fill::FILL_PATTERN_LIGHTVERTICAL = 'lightVertical';
PHPExcel_Style_Fill::FILL_PATTERN_MEDIUMGRAY = 'mediumGray';
'rotation' => (double)
'startcolor' => // See 'borders' => 'allborders' => 'color'
'endcolor' => // See 'borders' => 'allborders' => 'color'
'color' => // See 'borders' => 'allborders' => 'color'
)
'font' => array(
'name' =>
'Arial'
'Calibri'
// etc.
'bold' => (boolean)
'italic' => (boolean)
'superScript' => (boolean)
'subScript' => (boolean)
'underline' => (boolean)
'strike' => (boolean)
'size' => (float)
'color' => // See 'borders' => 'allborders' => 'color'
)
'numberformat' =>
'protection' =>
)
)
The default style for the entire workbook (all worksheets) can be set as:
$objPHPExcel->getDefaultStyle()
->getBorders()
->getTop()
->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$objPHPExcel->getDefaultStyle()
->getBorders()
->getBottom()
->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$objPHPExcel->getDefaultStyle()
->getBorders()
->getLeft()
->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$objPHPExcel->getDefaultStyle()
->getBorders()
->getRight()
->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
Also you can set as using applyFromArray()
$styleArray = array(
'borders' => array(
'allborders' => array(
'style' => PHPExcel_Style_Border::BORDER_THIN
)
)
);
$objPHPExcel->getDefaultStyle()->applyFromArray($styleArray);
So I've been going at this one for a while now. I'm trying to create a draggable table that has a parent-child relationship, but where the children cannot be moved out of the parent group, and all of the parents are sortable among each other. I've modeled my form and theme off of the admin menu code, and I have it duplicating that functionality. The problem is that I can move the children to another parent, or let it become a parent. As an illustration:
Category 1
|
|--Item 1
|--Item 2
Category 2
|
|--Item 3
|--Item 4
|--Item 5
I would like to be able to sort Item 1 and Item 2 with each other, and Item 3, Item 4, and Item 5 with each other, but not move them between Category 1 and Category 2. I also need to be able to sort Category 1 and Category 2 with one another, taking the children with them. I've went through so many combinations of $action, $group, $subgroup settings mixed with $class settings for the categories and items that I've lost track. Nothing I have tried so far has produced the desired result. Here's the relevant bits of my code as it is currently:
In my form:
$form['#tree'] = true;
foreach($categories as $cat) {
if(!isset($form['categories'][$cat->cid])){
$form['categories'][$cat->cid] = array(
'weight' => array(
'#type' => 'weight',
'#delta' => 25,
'#attributes' => array('class' => array('item-weight', 'item-weight-' . $cat->cid)),
),
'cid' => array(
'#type' => 'hidden',
'#value' => $cat->cid,
'#attributes' => array('class' => array('cid')),
),
);
foreach($cats[$cat->cid] as $item) {
$form['categories'][$cat->cid]['items'][$item->id] = array(
'weight' => array(
'#type' => 'weight',
'#delta' => 25,
'#default_value'=> $item->weight,
'#attributes' => array('class' => array('item-weight', 'item-weight-' . $cat->cid)),
),
'cid' => array(
'#type' => 'hidden',
'#value' => $cat->cid,
'#attributes' => array('class' => array('cid')),
),
);
}
}
}
In my theme:
$children = element_children($form['categories']);
$rows = array();
if(count($children) > 0) {
foreach($children as $cid) {
$row = array(
drupal_render($form['categories'][$cid]['weight']) .
drupal_render($form['categories'][$cid]['cid']),
);
$rows[] = array(
'data' => $row,
'class' => array('draggable', 'tabledrag-root'),
);
foreach(element_children($form['categories'][$cid]['items']) as $id) {
$row = array(
theme('indentation', array('size' => 1)) . drupal_render($form['categories'][$cid]['items'][$id]['name']),
drupal_render($form['categories'][$cid]['items'][$id]['weight']) .
drupal_render($form['categories'][$cid]['items'][$id]['cid']),
);
$rows[] = array(
'data' => $row,
'class' => array('draggable', 'tabledrag-leaf'),
);
}
drupal_add_tabledrag('cat-table', 'order', 'sibling', 'item-weight', 'item-weight-' . $cid);
}
}
drupal_add_tabledrag('cat-table', 'match', 'parent', 'cid', 'cid', 'cid', true, 1);
$output = theme('table', array('header' => $headers, 'rows' => $rows, 'attributes' => array('id' => 'cat-table')));
$output .= drupal_render_children($form);
return $output;
I've read over the documentation for drupal_add_tabledrag(), looked at the code, looked at example code, and searched around drupal.org and Google, but haven't come up with anything.
My only solution so far is to copy and modify the tabledrag.js file to just eliminate those capabilities, but while stopping the indent problem with the items (meaning, not letting them be on the same as the categories), keeping them in the same category has been Not Fun.
I suppose the most important question is, using standard Drupal is this possible?
I know you've already done a lot of coding so you might not want to give it up at this point, but DraggableViews is great to accomplish this. You can set up a normal view and add this draggableviews filter, it adds a weight and optionally a parent reference. The view itself uses the same drag-n-drop system as the rest of Drupal's backend tables.
Alternatively you can use a term reference and tie taxonomy terms to nodes, and just use that drag-n-drop.
If I'm missing something in your needs, my apologies, just thought I'd offer this simpler solution as it has definitely served me well in the past. Best of luck either way.
Just finished adding this functionality to my module
https://github.com/player259/ajax_table
There is no help, demo is outdated, but I'm working on it from time to time
Sections support was achieved by overriding tabledrag.js functions
Use this snippet to insert table
$form['map'] = array(
'#type' => 'ajax_table',
'#header' => array(t('Element'), t('Settings'), t('Weight')),
'rows' => array(),
'#draggable' => array(
// drupal_add_tabledrag will be called in theme layer
// NULL first arg to apply to this table
array(NULL, 'match', 'parent', 'perfect-form-parent', 'perfect-form-parent', 'perfect-form-index'),
array(NULL, 'depth', 'group', 'perfect-form-depth', NULL, NULL, FALSE),
array(NULL, 'order', 'sibling', 'perfect-form-weight'),
),
'#draggable_groups' => array(),
);
foreach ($map as $i => $element) {
// ... some logic
$form['map']['rows'][$i] = array(
'data' => array(
'element' => array(),
'settings' => array(),
'tabledrag' => array(
'index' => array(
'#type' => 'hidden',
'#value' => $element['data']['tabledrag']['index'],
'#attributes' => array('class' => array('perfect-form-index')),
),
'parent' => array(
'#type' => 'hidden',
'#default_value' => $element['data']['tabledrag']['parent'],
'#attributes' => array('class' => array('perfect-form-parent')),
),
'depth' => array(
'#type' => 'hidden',
'#default_value' => $element['data']['tabledrag']['depth'],
'#attributes' => array('class' => array('perfect-form-depth')),
),
'weight' => array(
'#type' => 'weight',
'#delta' => $max_weight,
'#default_value' => $weight,
'#attributes' => array('class' => array('perfect-form-weight')),
),
),
),
'#attributes' => array('class' => array($row_class_current, $row_class_child)),
);
// This means that row with $row_class_child class could have as parent
// only row with $row_class_parent class
// NULL means root - there are no parents
$form['map']['#draggable_groups'][$row_class_child] =
$depth ? $row_class_parent : NULL;
}
I had a similar problem at work so posting here my solution since none i found worked correctly in all situation. It is done 100% in javascript, on the php side you just have to set tabledrag in match with parent on pid and sort with siblings on weight.
The current code work on the example module (tabledrag parent/child) to adapt it to your need, change the .example-item-pid by your class for the PID input field. You just need to add it to the example code to have it working and see if it corresponds to your need.
First function invalidate any attempt to drop elements that don't have the same parent (PID) than the target element.
Second Function bypass the dragRow function to drop the element in the correct place (= the last children of the target row) and at the right depth ( = same depth than the target row).
/**
* Invalidate swap check if the row target is not of the same parent
* So we can only sort elements under the same parent and not move them to another parent
*
* #override Drupal.tableDrag.row.isValidSwap
*/
// Keep the original implementation - we still need it.
Drupal.tableDrag.prototype.row.prototype._isValidSwap = Drupal.tableDrag.prototype.row.prototype.isValidSwap;
Drupal.tableDrag.prototype.row.prototype.isValidSwap = function(row) {
if (this.indentEnabled) {
if (row && $('.example-item-pid', this.element).val() !== $('.example-item-pid', row).val()) {
return false;
}
}
// Return the original result.
return this._isValidSwap(row);
}
/**
* Position the dragged element under the last children of the element target for swapping when moving down our dragged element.
* Removed the indentation, since we can not change parent.
* #override Drupal.tableDrag.row.dragRow
*/
Drupal.tableDrag.prototype.dragRow = function (event, self) {
if (self.dragObject) {
self.currentMouseCoords = self.mouseCoords(event);
var y = self.currentMouseCoords.y - self.dragObject.initMouseOffset.y;
var x = self.currentMouseCoords.x - self.dragObject.initMouseOffset.x;
// Check for row swapping and vertical scrolling.
if (y != self.oldY) {
self.rowObject.direction = y > self.oldY ? 'down' : 'up';
self.oldY = y; // Update the old value.
// Check if the window should be scrolled (and how fast).
var scrollAmount = self.checkScroll(self.currentMouseCoords.y);
// Stop any current scrolling.
clearInterval(self.scrollInterval);
// Continue scrolling if the mouse has moved in the scroll direction.
if (scrollAmount > 0 && self.rowObject.direction == 'down' || scrollAmount < 0 && self.rowObject.direction == 'up') {
self.setScroll(scrollAmount);
}
// If we have a valid target, perform the swap and restripe the table.
var currentRow = self.findDropTargetRow(x, y);
if (currentRow) {
if (self.rowObject.direction == 'down') {
/**
* When going down we want to position the element after the last children and not right under the currentRow
*/
// create a new row prototype with currentRow
var rowObject = new self.row(currentRow, 'mouse', self.indentEnabled, self.maxDepth, false);
// extract all children
var childrenRows = rowObject.findChildren();
// if we have children
if (childrenRows.length > 0) {
// we change the row to swap with the last children
currentRow = childrenRows[childrenRows.length - 1];
}
self.rowObject.swap('after', currentRow, self);
}
else {
self.rowObject.swap('before', currentRow, self);
}
self.restripeTable();
}
}
/**
* We have disabled the indentation changes since it is not possible to change parent.
*/
return false;
}
};
I'm using fivestar 1.19 with voting axis. I believe the default fivestar block/fivestar function uses only the default 'vote' tag.
fivestar_widget_form($node)
I need to pass my custom fivestar tag to the function.
Attempting to follow the answer below:
For me $object is $node.
<?php
function custom_fivestar_widget ($object) {
global $user;
$star_display = variable_get('fivestar_style_'. $object->type, 'average');
$text_display = variable_get('fivestar_text_'. $object->type, 'dual');
if ($star_display == 'average' && ($text_display == 'average' || $text_display == 'none')) {
// Save a query and don't retrieve the user vote unnecessarily.
$votes = fivestar_get_votes($object->type, $object->nid, 'score', 0);
}
else {
$votes = fivestar_get_votes($object->type, $object->nid);
}
$values = array(
'user' => isset($votes['user']['value']) ? $votes['user']['value'] : 0,
'average' => isset($votes['average']['value']) ? $votes['average']['value'] : 0,
'count' => isset($votes['count']['value']) ? $votes['count']['value'] : 0,
);
$settings = array(
'stars' => variable_get('fivestar_stars_'. $object->type, 10),
'allow_clear' => variable_get('fivestar_unvote_'. $object->type, FALSE),
'style' => $star_display,
'text' => $text_display,
'content_type' => $object->type,
'content_id' => $object->nid,
'tag' => 'score',
'autosubmit' => TRUE,
'title' => variable_get('fivestar_title_'. $object->type, 1) ? NULL : FALSE,
'feedback_enable' => variable_get('fivestar_feedback_'. $object->type, 1),
'labels_enable' => variable_get('fivestar_labels_enable_'. $object->type, 1),
'labels' => variable_get('fivestar_labels_'. $object->type, array()),
);
return fivestar_custom_widget($form_state, $values, $settings);
}
print drupal_get_form('custom_fivestar_widget', $object);
?>
This prints me the widget, I believe using my score. However the text display is all wrong, as is the average score. And it gives everything a permanent 10 stars. :(
You can reproduce fivestar_form function in fivestar.module. See there $settings variable.
So just copy inner of this function, remove some variables checking and set manually some variables. In $settings array set to 'tag' value as you want.