I see we can't have control over modal size (via modal-dialog classes "modal-sm" and "modal-lg")
Wee can override bootstrap-modal.tpl.php and preprocess function but as it's easy to fix it, I open this "issue".
Solution :
In registry.inc
...
// Bootstrap Modals.
$hooks['bootstrap_modal'] = array(
'variables' => array(
'heading' => '',
'body' => '',
'footer' => '',
'attributes' => array(),
'size' => '' // waiting 'sm' or 'lg'
'html_heading' => FALSE,
),
);
...
In bootstrap-modal.vars.php
/**
* Implements theme_preprocess_bootstrap_modal().
*
* @todo: Replace with "bootstrap_effect_fade" theme setting.
*/
function bootstrap_preprocess_bootstrap_modal(&$variables) {
$variables['dialog_attributes'] = array(
'class' => array(
'modal-dialog'
)
);
if ($variables['size'] == 'sm' || $variables['size'] == 'lg') {
$variables['dialog_attributes']['class'][] = 'modal-' . $variables['size'];
}
}
/**
* Implements theme_process_bootstrap_modal().
*/
function bootstrap_process_bootstrap_modal(&$variables) {
$variables['attributes'] = drupal_attributes($variables['attributes']);
$variables['dialog_attributes'] = drupal_attributes($variables['dialog_attributes']);
$variables['body'] = render($variables['body']);
$variables['footer'] = render($variables['footer']);
}
function bootstrap_process_bootstrap_modal(&$variables) {
$variables['attributes'] = drupal_attributes($variables['attributes']);
$variables['size_class'] = !empty($variables['size']) ? 'dialog-' . $variables['size']
$variables['body'] = render($variables['body']);
$variables['footer'] = render($variables['footer']);
}
And finally in bootstrap-modal.tpl.php :
<?php
<div<?php print $attributes; ?>>
<div<?php print $dialog_attributes; ?>>
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title"><?php print $heading; ?></h4>
</div>
<div class="modal-body"><?php print $body; ?></div>
<div class="modal-footer"><?php print $footer; ?></div>
</div>
</div>
</div>
?>
What do you think about it ?
Regards
Comments
Comment #1
markhalliwellI think this is a good start, please create a patch. I'll be able to better review it then.
Comment #2
rroblik commentedfix code snippets display bug
Comment #3
rroblik commentedCan anybody push this into dev branch ?
Thanks for community : )
Comment #4
markhalliwellNo patch
Comment #5
rang501 commentedPatch created.
Comment #6
rang501 commentedComment #7
markhalliwellLet's rename this to
wrapper_attributes. This is a far more common name used in core/contrib.The following should be added to the initial theme hook definition:
Instead of backing ourselves into a corner here, let's add the size if it's present (e.g. no checking if it's "sm" or "lg"). It should also be added using drupal_html_class so it can properly sanitize the input.
This should changed to following so it doesn't overwrite the entire wrapper attributes array (if one was initially provided in the theme hook implementation):
Comment #8
rang501 commentedMade the required changes.
Comment #9
rang501 commentedComment #10
markhalliwellAwesome :) Thanks for the patches!
Just one more tiny nitpick:
This doesn't need
issetas!emptywill also check if the variable exists. Bothissetandemptyare PHP language constructs. They're not actually functions, so neither will throw and error if the variable doesn't exist.Comment #11
rang501 commentedYou are right :)
Hopefully this is ok now.
Comment #12
markhalliwellSo, I was about to commit this and then I just saw this in the diff:
A "wrapper" div should be on the outside and obviously we can't rename "attributes" as that would be a backwards compatibility break. So I suppose we should go with the original variable name
$dialog_attributes. I'll make the change and then commit shortly. Needs a change record since it's touching a template file.Comment #15
markhalliwell