2007-09-14 12:17:58 +00:00
< ? php
// $Id$
/**
* @ file
* Admin page callbacks for the filter module .
*/
/**
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
* Menu callback ; Displays a list of all text formats and allows them to be rearranged .
2007-09-14 12:17:58 +00:00
*
* @ ingroup forms
2008-01-08 10:35:43 +00:00
* @ see filter_admin_overview_submit ()
2007-09-14 12:17:58 +00:00
*/
2009-09-18 00:12:48 +00:00
function filter_admin_overview ( $form ) {
2007-09-14 12:17:58 +00:00
// Overview of all formats.
$formats = filter_formats ();
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
$fallback_format = filter_fallback_format ();
2007-09-14 12:17:58 +00:00
2009-09-18 00:12:48 +00:00
$form [ '#tree' ] = TRUE ;
2007-09-14 12:17:58 +00:00
foreach ( $formats as $id => $format ) {
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
// Check whether this is the fallback text format. This format is available
// to all roles and cannot be deleted via the admin interface.
$form [ 'formats' ][ $id ][ '#is_fallback' ] = ( $id == $fallback_format );
if ( $form [ 'formats' ][ $id ][ '#is_fallback' ]) {
2009-10-09 01:00:08 +00:00
$form [ 'formats' ][ $id ][ 'name' ] = array ( '#markup' => theme ( 'placeholder' , array ( 'text' => $format -> name )));
$roles_markup = theme ( 'placeholder' , array ( 'text' => t ( 'All roles may use this format' )));
2007-09-14 12:17:58 +00:00
}
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
else {
$form [ 'formats' ][ $id ][ 'name' ] = array ( '#markup' => check_plain ( $format -> name ));
$roles = filter_get_roles_by_format ( $format );
$roles_markup = $roles ? implode ( ', ' , $roles ) : t ( 'No roles may use this format' );
}
$form [ 'formats' ][ $id ][ 'roles' ] = array ( '#markup' => $roles_markup );
2009-11-03 05:27:18 +00:00
$form [ 'formats' ][ $id ][ 'configure' ] = array ( '#type' => 'link' , '#title' => t ( 'configure' ), '#href' => 'admin/config/content/formats/' . $id );
$form [ 'formats' ][ $id ][ 'delete' ] = array ( '#type' => 'link' , '#title' => t ( 'delete' ), '#href' => 'admin/config/content/formats/' . $id . '/delete' , '#access' => ! $form [ 'formats' ][ $id ][ '#is_fallback' ]);
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
$form [ 'formats' ][ $id ][ 'weight' ] = array ( '#type' => 'weight' , '#default_value' => $format -> weight );
2007-09-14 12:17:58 +00:00
}
2008-02-19 14:07:21 +00:00
$form [ 'submit' ] = array ( '#type' => 'submit' , '#value' => t ( 'Save changes' ));
2007-09-14 12:17:58 +00:00
return $form ;
}
function filter_admin_overview_submit ( $form , & $form_state ) {
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
foreach ( $form_state [ 'values' ][ 'formats' ] as $id => $data ) {
2008-02-19 14:07:21 +00:00
if ( is_array ( $data ) && isset ( $data [ 'weight' ])) {
// Only update if this is a form element with weight.
2009-04-25 18:01:10 +00:00
db_update ( 'filter_format' )
-> fields ( array ( 'weight' => $data [ 'weight' ]))
-> condition ( 'format' , $id )
-> execute ();
2008-02-19 14:07:21 +00:00
}
}
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
filter_formats_reset ();
2009-01-21 16:58:42 +00:00
drupal_set_message ( t ( 'The text format ordering has been saved.' ));
2007-09-14 12:17:58 +00:00
}
/**
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
* Theme the text format administration overview form .
2007-09-14 12:17:58 +00:00
*
* @ ingroup themeable
*/
2009-10-09 01:00:08 +00:00
function theme_filter_admin_overview ( $variables ) {
$form = $variables [ 'form' ];
2007-09-14 12:17:58 +00:00
$rows = array ();
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
foreach ( element_children ( $form [ 'formats' ]) as $id ) {
$form [ 'formats' ][ $id ][ 'weight' ][ '#attributes' ][ 'class' ] = array ( 'text-format-order-weight' );
$rows [] = array (
'data' => array (
drupal_render ( $form [ 'formats' ][ $id ][ 'name' ]),
drupal_render ( $form [ 'formats' ][ $id ][ 'roles' ]),
drupal_render ( $form [ 'formats' ][ $id ][ 'weight' ]),
drupal_render ( $form [ 'formats' ][ $id ][ 'configure' ]),
drupal_render ( $form [ 'formats' ][ $id ][ 'delete' ]),
),
'class' => array ( 'draggable' ),
);
2007-09-14 12:17:58 +00:00
}
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
$header = array ( t ( 'Name' ), t ( 'Roles' ), t ( 'Weight' ), array ( 'data' => t ( 'Operations' ), 'colspan' => 2 ));
2009-10-09 01:00:08 +00:00
$output = theme ( 'table' , array ( 'header' => $header , 'rows' => $rows , 'attributes' => array ( 'id' => 'text-format-order' )));
2009-02-03 18:55:32 +00:00
$output .= drupal_render_children ( $form );
2007-09-14 12:17:58 +00:00
2009-03-08 21:25:18 +00:00
drupal_add_tabledrag ( 'text-format-order' , 'order' , 'sibling' , 'text-format-order-weight' );
2008-02-19 14:07:21 +00:00
2007-09-14 12:17:58 +00:00
return $output ;
}
2007-09-17 09:16:48 +00:00
/**
2009-03-08 21:25:18 +00:00
* Menu callback ; Display a text format form .
2007-09-17 09:16:48 +00:00
*/
function filter_admin_format_page ( $format = NULL ) {
if ( ! isset ( $format -> name )) {
2009-10-13 15:39:41 +00:00
drupal_set_title ( t ( 'Add text format' ));
$format = ( object ) array ( 'name' => '' , 'format' => 0 );
2007-09-17 09:16:48 +00:00
}
return drupal_get_form ( 'filter_admin_format_form' , $format );
}
2007-09-14 12:17:58 +00:00
/**
2009-03-08 21:25:18 +00:00
* Generate a text format form .
2007-09-14 12:17:58 +00:00
*
* @ ingroup forms
2008-01-08 10:35:43 +00:00
* @ see filter_admin_format_form_validate ()
* @ see filter_admin_format_form_submit ()
2007-09-14 12:17:58 +00:00
*/
2009-09-18 00:12:48 +00:00
function filter_admin_format_form ( $form , & $form_state , $format ) {
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
$is_fallback = ( $format -> format == filter_fallback_format ());
if ( $is_fallback ) {
$help = t ( 'All roles for this text format must be enabled and cannot be changed.' );
2007-09-14 12:17:58 +00:00
}
2009-09-11 15:39:48 +00:00
$form [ 'name' ] = array (
'#type' => 'textfield' ,
2008-02-14 18:39:18 +00:00
'#title' => t ( 'Name' ),
2007-09-14 12:17:58 +00:00
'#default_value' => $format -> name ,
2009-03-08 21:25:18 +00:00
'#description' => t ( 'Specify a unique name for this text format.' ),
2007-09-14 12:17:58 +00:00
'#required' => TRUE ,
);
// Add a row of checkboxes for form group.
$form [ 'roles' ] = array ( '#type' => 'fieldset' ,
'#title' => t ( 'Roles' ),
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
'#description' => $is_fallback ? $help : t ( 'Choose which roles may use this text format. Note that roles with the "administer filters" permission can always use all text formats.' ),
2007-09-14 12:17:58 +00:00
'#tree' => TRUE ,
);
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
$checked = filter_get_roles_by_format ( $format );
2007-09-14 12:17:58 +00:00
foreach ( user_roles () as $rid => $name ) {
$form [ 'roles' ][ $rid ] = array ( '#type' => 'checkbox' ,
'#title' => $name ,
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
'#default_value' => ( $is_fallback || isset ( $checked [ $rid ])),
2007-09-14 12:17:58 +00:00
);
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
if ( $is_fallback ) {
2007-09-14 12:17:58 +00:00
$form [ 'roles' ][ $rid ][ '#disabled' ] = TRUE ;
}
}
// Table with filters
2009-08-25 10:35:33 +00:00
$filter_info = filter_get_filters ();
2009-11-22 08:14:27 +00:00
$filters = filter_list_format ( $format -> format );
2007-09-14 12:17:58 +00:00
$form [ 'filters' ] = array ( '#type' => 'fieldset' ,
'#title' => t ( 'Filters' ),
2009-03-08 21:25:18 +00:00
'#description' => t ( 'Choose the filters that will be used in this text format.' ),
2007-09-14 12:17:58 +00:00
'#tree' => TRUE ,
);
2009-08-25 10:35:33 +00:00
foreach ( $filter_info as $name => $filter ) {
2009-09-11 15:39:48 +00:00
$form [ 'filters' ][ $name ][ 'status' ] = array (
2009-08-25 10:35:33 +00:00
'#type' => 'checkbox' ,
'#title' => $filter [ 'title' ],
2009-09-11 15:39:48 +00:00
'#default_value' => ! empty ( $filters [ $name ] -> status ),
2009-08-25 10:35:33 +00:00
'#description' => $filter [ 'description' ],
2007-09-14 12:17:58 +00:00
);
}
2007-09-17 09:16:48 +00:00
if ( ! empty ( $format -> format )) {
2007-09-14 12:17:58 +00:00
$form [ 'format' ] = array ( '#type' => 'hidden' , '#value' => $format -> format );
// Composition tips (guidelines)
$tips = _filter_tips ( $format -> format , FALSE );
2009-10-09 01:00:08 +00:00
$tiplist = theme ( 'filter_tips' , array ( 'tips' => $tips , 'long' => FALSE ));
2007-09-14 12:17:58 +00:00
if ( ! $tiplist ) {
2008-04-14 17:48:46 +00:00
$tiplist = '<p>' . t ( 'No guidelines available.' ) . '</p>' ;
2007-09-14 12:17:58 +00:00
}
2008-12-03 19:43:21 +00:00
else {
$tiplist .= theme ( 'filter_tips_more_info' );
}
2009-01-21 16:58:42 +00:00
$group = '<p>' . t ( 'These are the guidelines that users will see for posting in this text format. They are automatically generated from the filter settings.' ) . '</p>' ;
2007-09-14 12:17:58 +00:00
$group .= $tiplist ;
2008-07-16 21:59:29 +00:00
$form [ 'tips' ] = array ( '#markup' => '<h2>' . t ( 'Formatting guidelines' ) . '</h2>' . $group );
2007-09-14 12:17:58 +00:00
}
$form [ 'submit' ] = array ( '#type' => 'submit' , '#value' => t ( 'Save configuration' ));
return $form ;
}
/**
2009-03-08 21:25:18 +00:00
* Validate text format form submissions .
2007-09-14 12:17:58 +00:00
*/
function filter_admin_format_form_validate ( $form , & $form_state ) {
if ( ! isset ( $form_state [ 'values' ][ 'format' ])) {
2009-08-25 10:35:33 +00:00
$format_name = trim ( $form_state [ 'values' ][ 'name' ]);
$result = db_query ( " SELECT format FROM { filter_format} WHERE name = :name " , array ( ':name' => $format_name )) -> fetchField ();
2007-09-14 12:17:58 +00:00
if ( $result ) {
2009-08-21 17:28:27 +00:00
form_set_error ( 'name' , t ( 'Text format names must be unique. A format named %name already exists.' , array ( '%name' => $format_name )));
2007-09-14 12:17:58 +00:00
}
}
}
/**
2009-03-08 21:25:18 +00:00
* Process text format form submissions .
2007-09-14 12:17:58 +00:00
*/
function filter_admin_format_form_submit ( $form , & $form_state ) {
2009-08-26 04:59:26 +00:00
$format = ( object ) $form_state [ 'values' ];
$format -> format = isset ( $form_state [ 'values' ][ 'format' ]) ? $form_state [ 'values' ][ 'format' ] : NULL ;
$status = filter_format_save ( $format );
2007-09-14 12:17:58 +00:00
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
if ( $permission = filter_permission_name ( $format )) {
foreach ( $format -> roles as $rid => $enabled ) {
user_role_change_permissions ( $rid , array ( $permission => $enabled ));
}
}
2009-08-26 04:59:26 +00:00
switch ( $status ) {
case SAVED_NEW :
drupal_set_message ( t ( 'Added text format %format.' , array ( '%format' => $format -> name )));
break ;
2009-08-27 21:18:20 +00:00
2009-08-26 04:59:26 +00:00
case SAVED_UPDATED :
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
drupal_set_message ( t ( 'The text format %format has been updated.' , array ( '%format' => $format -> name )));
2009-08-26 04:59:26 +00:00
break ;
2007-09-14 12:17:58 +00:00
}
}
/**
* Menu callback ; confirm deletion of a format .
*
* @ ingroup forms
2008-01-08 10:35:43 +00:00
* @ see filter_admin_delete_submit ()
2007-09-14 12:17:58 +00:00
*/
2009-09-18 00:12:48 +00:00
function filter_admin_delete ( $form , & $form_state , $format ) {
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
$form [ '#format' ] = $format ;
return confirm_form ( $form ,
t ( 'Are you sure you want to delete the text format %format?' , array ( '%format' => $format -> name )),
'admin/config/content/formats' ,
t ( 'If you have any content left in this text format, it will be switched to the %fallback text format. This action cannot be undone.' , array ( '%fallback' => filter_fallback_format_title ())),
t ( 'Delete' ),
t ( 'Cancel' )
);
2007-09-14 12:17:58 +00:00
}
/**
* Process filter delete form submission .
*/
function filter_admin_delete_submit ( $form , & $form_state ) {
2009-08-26 10:29:26 +00:00
$format = $form [ '#format' ];
filter_format_delete ( $format );
drupal_set_message ( t ( 'Deleted text format %format.' , array ( '%format' => $format -> name )));
2007-09-14 12:17:58 +00:00
2009-08-28 16:23:05 +00:00
$form_state [ 'redirect' ] = 'admin/config/content/formats' ;
2007-09-14 12:17:58 +00:00
}
2007-09-17 09:16:48 +00:00
/**
* Menu callback ; display settings defined by a format ' s filters .
*/
function filter_admin_configure_page ( $format ) {
2008-10-13 00:33:05 +00:00
drupal_set_title ( t ( " Configure %format " , array ( '%format' => $format -> name )), PASS_THROUGH );
2007-09-17 09:16:48 +00:00
return drupal_get_form ( 'filter_admin_configure' , $format );
}
2007-09-14 12:17:58 +00:00
/**
2009-08-27 21:18:20 +00:00
* Build a form to change the settings for filters in a text format .
*
* The form is built by merging the results of 'settings callback' for each
* enabled filter in the given format .
2007-09-14 12:17:58 +00:00
*
* @ ingroup forms
*/
2009-09-18 00:12:48 +00:00
function filter_admin_configure ( $form , & $form_state , $format ) {
2009-08-27 21:18:20 +00:00
$filters = filter_list_format ( $format -> format );
2009-08-25 10:35:33 +00:00
$filter_info = filter_get_filters ();
2009-08-27 21:18:20 +00:00
$form [ '#format' ] = $format ;
foreach ( $filters as $name => $filter ) {
2009-11-22 08:14:27 +00:00
if ( $filter -> status && isset ( $filter_info [ $name ][ 'settings callback' ]) && function_exists ( $filter_info [ $name ][ 'settings callback' ])) {
2009-08-27 21:18:20 +00:00
// Pass along stored filter settings and default settings, but also the
// format object and all filters to allow for complex implementations.
$defaults = ( isset ( $filter_info [ $name ][ 'default settings' ]) ? $filter_info [ $name ][ 'default settings' ] : array ());
2009-09-18 00:12:48 +00:00
$settings_form = $filter_info [ $name ][ 'settings callback' ]( $form , $form_state , $filters [ $name ], $defaults , $format , $filters );
2009-11-22 08:14:27 +00:00
if ( ! empty ( $settings_form )) {
2009-08-27 21:18:20 +00:00
$form [ 'settings' ][ $name ] = array (
'#type' => 'fieldset' ,
'#title' => check_plain ( $filter -> title ),
);
$form [ 'settings' ][ $name ] += $settings_form ;
}
2007-09-14 12:17:58 +00:00
}
}
2009-08-27 21:18:20 +00:00
if ( empty ( $form [ 'settings' ])) {
2008-07-16 21:59:29 +00:00
$form [ 'error' ] = array ( '#markup' => t ( 'No settings are available.' ));
2009-08-27 21:18:20 +00:00
return $form ;
2007-09-14 12:17:58 +00:00
}
2009-08-27 21:18:20 +00:00
$form [ 'settings' ][ '#tree' ] = TRUE ;
$form [ 'submit' ] = array ( '#type' => 'submit' , '#value' => t ( 'Save configuration' ));
2007-09-14 12:17:58 +00:00
return $form ;
}
2007-12-21 11:58:59 +00:00
/**
2009-08-27 21:18:20 +00:00
* Form submit handler for text format filter configuration form .
*
* @ see filter_admin_configure ()
2007-12-21 11:58:59 +00:00
*/
function filter_admin_configure_submit ( $form , & $form_state ) {
2009-08-27 21:18:20 +00:00
$format = $form [ '#format' ];
foreach ( $form_state [ 'values' ][ 'settings' ] as $name => $settings ) {
db_update ( 'filter' )
-> fields ( array (
'settings' => serialize ( $settings ),
))
-> condition ( 'format' , $format -> format )
-> condition ( 'name' , $name )
-> execute ();
}
// Clear the filter's cache when configuration settings are saved.
cache_clear_all ( $format -> format . ':' , 'cache_filter' , TRUE );
drupal_set_message ( t ( 'The configuration options have been saved.' ));
2007-12-21 11:58:59 +00:00
}
2007-09-14 12:17:58 +00:00
/**
* Menu callback ; display form for ordering filters for a format .
2007-09-17 09:16:48 +00:00
*/
function filter_admin_order_page ( $format ) {
2008-10-13 00:33:05 +00:00
drupal_set_title ( t ( " Rearrange %format " , array ( '%format' => $format -> name )), PASS_THROUGH );
2007-09-17 09:16:48 +00:00
return drupal_get_form ( 'filter_admin_order' , $format );
}
/**
* Build the form for ordering filters for a format .
2007-09-14 12:17:58 +00:00
*
* @ ingroup forms
2008-01-08 10:35:43 +00:00
* @ see theme_filter_admin_order ()
* @ see filter_admin_order_submit ()
2007-09-14 12:17:58 +00:00
*/
2009-09-18 00:12:48 +00:00
function filter_admin_order ( $form , & $form_state , $format = NULL ) {
2007-09-14 12:17:58 +00:00
// Get list (with forced refresh).
$filters = filter_list_format ( $format -> format );
$form [ 'weights' ] = array ( '#tree' => TRUE );
foreach ( $filters as $id => $filter ) {
2009-11-22 08:14:27 +00:00
if ( $filter -> status ) {
$form [ 'names' ][ $id ] = array ( '#markup' => $filter -> title );
$form [ 'weights' ][ $id ] = array ( '#type' => 'weight' , '#default_value' => $filter -> weight );
}
2007-09-14 12:17:58 +00:00
}
$form [ 'format' ] = array ( '#type' => 'hidden' , '#value' => $format -> format );
$form [ 'submit' ] = array ( '#type' => 'submit' , '#value' => t ( 'Save configuration' ));
return $form ;
}
/**
* Theme filter order configuration form .
2007-12-06 09:58:34 +00:00
*
* @ ingroup themeable
2007-09-14 12:17:58 +00:00
*/
2009-10-09 01:00:08 +00:00
function theme_filter_admin_order ( $variables ) {
$form = $variables [ 'form' ];
2007-09-14 12:17:58 +00:00
$header = array ( t ( 'Name' ), t ( 'Weight' ));
$rows = array ();
foreach ( element_children ( $form [ 'names' ]) as $id ) {
// Don't take form control structures.
if ( is_array ( $form [ 'names' ][ $id ])) {
2009-08-22 14:34:23 +00:00
$form [ 'weights' ][ $id ][ '#attributes' ][ 'class' ] = array ( 'filter-order-weight' );
2007-11-20 20:13:04 +00:00
$rows [] = array (
'data' => array ( drupal_render ( $form [ 'names' ][ $id ]), drupal_render ( $form [ 'weights' ][ $id ])),
2009-08-22 14:34:23 +00:00
'class' => array ( 'draggable' ),
2007-11-20 20:13:04 +00:00
);
2007-09-14 12:17:58 +00:00
}
}
2009-10-09 01:00:08 +00:00
$output = theme ( 'table' , array ( 'header' => $header , 'rows' => $rows , 'attributes' => array ( 'id' => 'filter-order' )));
2009-02-03 18:55:32 +00:00
$output .= drupal_render_children ( $form );
2007-09-14 12:17:58 +00:00
2007-11-20 20:13:04 +00:00
drupal_add_tabledrag ( 'filter-order' , 'order' , 'sibling' , 'filter-order-weight' , NULL , NULL , FALSE );
2007-11-23 13:34:55 +00:00
2007-09-14 12:17:58 +00:00
return $output ;
}
/**
* Process filter order configuration form submission .
*/
function filter_admin_order_submit ( $form , & $form_state ) {
2009-08-25 10:35:33 +00:00
foreach ( $form_state [ 'values' ][ 'weights' ] as $name => $weight ) {
2009-08-27 21:18:20 +00:00
db_merge ( 'filter' )
-> key ( array (
'format' => $form_state [ 'values' ][ 'format' ],
'name' => $name ,
))
-> fields ( array (
'weight' => $weight ,
))
2009-04-25 18:01:10 +00:00
-> execute ();
2007-09-14 12:17:58 +00:00
}
drupal_set_message ( t ( 'The filter ordering has been saved.' ));
2008-04-14 17:48:46 +00:00
cache_clear_all ( $form_state [ 'values' ][ 'format' ] . ':' , 'cache_filter' , TRUE );
2007-09-14 12:17:58 +00:00
}