Comments

duellj’s picture

Status: Active » Needs review

Currently, this doesn't handle operand parameters beyond adding in a TODO comment. If needed, I could work on checking the assignment of the operand, but I think a comment should be fine. Another option would be to add a foreach loop around drupal_add_library(), but we would have to make sure the operand parameter is an array.

Upgrade routine:

/**
 * Implements hook_upgrade_call_jquery_ui_add_alter().
 */
function coder_upgrade_upgrade_call_jquery_ui_add_alter(&$item, &$reader) {
  // Create helper objects.
  $editor = PGPEditor::getInstance();
  
  // jquery_ui_add is now drupal_add_library, and takes single parameters instead of arrays
  $operand = $item->getParameter()->getElement();
  
  // Examine the type of the operand in the parameter.
  if (get_class($operand) == 'PGPArray') {
    $current = $operand->values->first();
    while ($current->next != NULL) {
      if ($current->type == 'value') {
        $values[] = $current->data->toString();
      }
      $current = $current->next;
    }
    $editor->setParameter($item, 0, array_pop($values));
    if ($values) {
      $parent = &$item->parent;
      $container = &$parent->container;
      foreach ($values as $value) {
        $temp = $editor->textToStatements("drupal_add_library('system', {$value})")->getElement();
        $container->insertBefore($parent, $temp);
      }
    }
  }
  elseif (get_class($operand) == 'PGPOperand') {
    $temp = $editor->commentToStatement("// TODO {$operand->toString()} needs to be a string or multiple calls to drupal_add_library need to be made.");
    $parent = &$item->parent;
    $container = &$parent->container;
    $container->insertBefore($parent, $temp, 'comment');
  }
  $editor->insertParameter($item, 0, "'system'");
  $name = &$item->name;
  $name['value'] = 'drupal_add_library';
}

Test function:

function example_jquery_ui_add() {
  jquery_ui_add(array('ui.accordion', 'ui.dialog'));
  jquery_ui_add('ui.accordion');
  $files = array('ui.accordion', 'ui.dialog');
  jquery_ui_add($files);
}
solotandem’s picture

Implemented in next dev release. Modified code to handled the parameter being a variable. Added more cases to example function above.

solotandem’s picture

Assigned: Unassigned » solotandem
Status: Needs review » Fixed

Implemented in next dev release. Modified code to handled the parameter being a variable. Added more cases to example function above.

Status: Fixed » Closed (fixed)
Issue tags: -Intermediate

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