Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

devel_variable*() functions missing. #55

Open
klonos opened this issue May 29, 2019 · 2 comments
Open

devel_variable*() functions missing. #55

klonos opened this issue May 29, 2019 · 2 comments

Comments

@klonos
Copy link
Member

klonos commented May 29, 2019

In devel.pages.inc, between devel_field_info_page() and devel_session():

/**
 * Form constructor for displaying and editing variables.
 *
 * @see devel_variable_form_submit()
 *
 * @ingroup forms.
 */
function devel_variable_form() {
  $header = array(
    'name' => array('data' => t('Name'), 'field' => 'name', 'sort' => 'asc'),
    'value' => array('data' => t('Value'), 'field' => 'value'),
    'length' => array('data' => t('Length'), 'field' => 'length'),
    'edit' => array('data' => t('Operations')),
  );
  // @todo: We could get variables out of $conf but that would include
  // hard-coded ones too. Ideally I would highlight overridden/hard-coded
  // variables.
  $query = db_select('variable', 'v')->extend('TableSort');
  $query->fields('v', array('name', 'value'));
  switch (db_driver()) {
  return $form;
}
/**
 * Form submission handler for devel_variable_form().
 */
function devel_variable_form_submit($form, &$form_state) {
  $deletes = array_filter($form_state['values']['variables']);
  array_walk($deletes, 'variable_del');
  if (count($deletes)) {
    drupal_set_message(format_plural(count($deletes), 'One variable deleted.', '@count variables deleted.'));
  }
}
/**
 * After build callback for devel_variable_form().
 *
 * Wrap each variable name in a <label> element.
 */
function devel_variable_form_after_build($form, &$form_state) {
  foreach ($form['variables']['#options'] as $variable => $element) {
    $form['variables']['#options'][$variable]['name'] = '<label for="' . $form['variables'][$variable]['#id'] . '">' . $element['name'] . '</label>';
  }
  return $form;
}
/**
 * Form constructor for editing a variable.
 *
 * @see devel_variable_edit_submit()
 *
 * @ingroup forms
 */
function devel_variable_edit($form, &$form_state, $name) {
  $value = variable_get($name, 'not found');
  $form['name'] = array(
    '#type' => 'value',
    '#value' => $name
  );
  $form['value'] = array(
    '#type' => 'item',
    '#title' => t('Old value'),
    '#markup' => dpr($value, TRUE),
  );
  if (is_string($value) || is_numeric($value)) {
    $form['new'] = array(
      '#type' => 'textarea',
      '#title' => t('New value'),
      '#default_value' => $value
    );
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Submit'),
    );
  }
  else {
    $api = variable_get('devel_api_url', 'api.drupal.org');
    $form['new'] = array(
      '#type' => 'item',
      '#title' => t('New value'),
      '#markup' => t('Sorry, complex variable types may not be edited yet. Use the <em>Execute PHP</em> block and the <a href="@variable-set-doc">variable_set()</a> function.', array('@variable-set-doc' => "http://$api/api/HEAD/function/variable_set"))
    );
  }
  drupal_set_title($name);
  return $form;
}
/**
 * Form submission handler for devel_variable_edit().
 */
function devel_variable_edit_submit($form, &$form_state) {
  variable_set($form_state['values']['name'], $form_state['values']['new']);
  drupal_set_message(t('Saved new value for %name.', array('%name' => $form_state['values']['name'])));
   'devel/variable';
}
@klonos
Copy link
Member Author

klonos commented May 29, 2019

...we have moved to config in Backdrop. So does it make sense to have respective functions, or should we provide deprecated wrapper functions for them?

@quicksketch
Copy link
Member

Hm, Backdrop does still have the variables table, even though it's not used in core and deprecated. I'm not much a fan of including functionality for it in Devel.

As for an analogue in Backdrop, editing config files is much easier than manipulating a database table with serialized values. And if you want a UI for editing values, you can use the existing config import UI to modify individual files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants