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">&times;</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

markhalliwell’s picture

I think this is a good start, please create a patch. I'll be able to better review it then.

rroblik’s picture

Issue summary: View changes

fix code snippets display bug

rroblik’s picture

Status: Active » Needs work

Can anybody push this into dev branch ?

Thanks for community : )

markhalliwell’s picture

Status: Needs work » Active

No patch

rang501’s picture

StatusFileSize
new2.03 KB

Patch created.

rang501’s picture

Status: Active » Needs review
markhalliwell’s picture

Component: Theme settings » Templates
Status: Needs review » Needs work
  1. +++ b/templates/bootstrap/bootstrap-modal.tpl.php
    @@ -13,7 +13,7 @@
    +  <div<?php print $dialog_attributes; ?>>
    
    +++ b/templates/bootstrap/bootstrap-modal.vars.php
    @@ -27,6 +37,7 @@ function bootstrap_preprocess_bootstrap_modal(&$variables) {
    +  $variables['dialog_attributes'] = drupal_attributes($variables['dialog_attributes']);
    

    Let'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:

    'wrapper_attributes' => array(),
    
  2. +++ b/includes/registry.inc
    @@ -80,6 +80,7 @@ function _bootstrap_theme(&$existing, $type, $theme, $path) {
    +      'size' => '',
    
    +++ b/templates/bootstrap/bootstrap-modal.vars.php
    @@ -20,6 +20,16 @@ function bootstrap_preprocess_bootstrap_modal(&$variables) {
    +  if ($variables['size'] === 'sm' || $variables['size'] === 'lg') {
    

    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.

  3. +++ b/templates/bootstrap/bootstrap-modal.vars.php
    @@ -20,6 +20,16 @@ function bootstrap_preprocess_bootstrap_modal(&$variables) {
    +  $variables['dialog_attributes'] = array(
    +    'class' => array(
    +      'modal-dialog'
    +    )
    +  );
    

    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):

    $variables['wrapper_attributes']['class'][] = 'modal-dialog';
    
rang501’s picture

StatusFileSize
new2.08 KB

Made the required changes.

rang501’s picture

Status: Needs work » Needs review
markhalliwell’s picture

Status: Needs review » Needs work

Awesome :) Thanks for the patches!

Just one more tiny nitpick:

+++ b/templates/bootstrap/bootstrap-modal.vars.php
@@ -20,6 +20,11 @@ function bootstrap_preprocess_bootstrap_modal(&$variables) {
+  if (isset($variables['size']) && !empty($variables['size'])) {

This doesn't need isset as !empty will also check if the variable exists. Both isset and empty are PHP language constructs. They're not actually functions, so neither will throw and error if the variable doesn't exist.

rang501’s picture

Status: Needs work » Needs review
StatusFileSize
new2.05 KB

You are right :)
Hopefully this is ok now.

markhalliwell’s picture

So, I was about to commit this and then I just saw this in the diff:

<div<?php print $attributes; ?>>
  <div<?php print $wrapper_attributes; ?>>

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.

  • markcarver committed 24039d0 on 7.x-3.x authored by rang501
    Issue #2317763 by rang501, rroblik: Add modal dialog class size variable
    

  • markcarver committed cadc2c2 on authored by rang501
    Issue #2317763 by rang501, rroblik: Add modal dialog class size variable
    
markhalliwell’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.