CVS edit link for fending

[Note: this is the second submission, first one denied because code was not uploaded in a timely fashion. I was waiting on the toolbar vendor to ensure me they wouldn't change the API without a heads up (See last paragraph) and were cool / totally onboard with the module. I got that okay this morning, so the files may now be uploaded.]

I have written a module that adds the Extendy (www.extendy.com) widget toolbar to a Drupal site. From their site: "Extendy lets visitors share their favorite pages, search your content, view your latest tweets and blog posts, connect with you across social networks, and more."

The module accepts an API key, which in turn fetches "campaign id and name" from extendy.com and adds some js to the Drupal site to invoke the toolbar. Further configury of the Extendy toolbar (colors, styles, which widgets to expose, etc) is done at extendy.com.

I am in communication with a principal at InSeconds (the dev shop for extendy) about their API plans to ensure my implementation methods will be supported moving forward. I'd really like permission to add extendy.module to the contrib repos and help our community adopt this as easily as the WordPress community has done using the vendor-supplied WP plugin.

Thanks!/BF

CommentFileSizeAuthor
#1 extendy.tar_.gz10.6 KBfending

Comments

fending’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new10.6 KB

First module submission - please be gentle! :)

avpaderno’s picture

Issue tags: +Module review
avpaderno’s picture

Status: Needs review » Needs work
  1. The file LICENSE.txt needs to be removed; Drupal.org CVS doesn't allow to commit that file.
  2. include_once('./' . drupal_get_path('module', 'extendy') . '/includes/extendy.api.inc');
    

    If you are going to unconditionally include the file, then it is better to merge the two files.

  3.     'title' => t('Extendy Settings'),
        'page callback' => 'drupal_get_form',
        'page arguments' => array('extendy_settings'),
        'access arguments' => array('extendy settings'),
    

    Menu callback titles, and descriptions should not be passed to t() because that is already done by Drupal core code.

  4.     '#default_value' => variable_get('extendy_key', ''),
        '#description' => t('If you don\'t have an Extendy account (to get a Campaign API Key), <a href="http://www.extendy.com/signup">create an account at extendy.com</a> and copy the Campign API Key for this Campaign from the WordPress tab.'),
    

    Avoid to escape the delimiter inside a string that needs to be translated; if the URL is not translated with a different language, then you should use a placeholder.

  5.     '#weight' => '10',
        '#attributes' => array('readonly' => 'readonly'),
        '#default_value' => variable_get('extendy_campaign_id', ''),
    

    If you want to disable a form field, Drupal uses a different method.

  6. function extendy_settings_validate($form, &$form_state) {
    
      if ($form_state['values']['op'] != t('Reset to defaults')) {
        if (drupal_strlen($form_state['values']['extendy_key'])==0) {
          form_set_error('extendy_key', t("This field is required"));
        }
      }
    
    }
    

    If you need to be sure a value requested with a form will be returned there is an easier way that requires you to write a single line of code.

  7. /**
     * Submit the settings form values
     */
    function extendy_settings_form_submit($form, &$form_state) {
      $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
    
      // Exclude unnecessary elements.
      unset($form_state['values']['submit'], $form_state['values']['reset'], $form_state['values']['form_id'], $form_state['values']['op'], $form_state['values']['form_token'], $form_state['values']['form_build_id']);
    
      foreach ($form_state['values'] as $key => $value) {
        if ($op == t('Reset to defaults')) {
          variable_del($key);
          unset($form_state['values'][$key]);
        }
        else {
          if (is_array($value) && isset($form_state['values']['array_filter'])) {
            $value = array_keys(array_filter($value));
          }
          variable_set($key, $value);
        }
      }
    
      if ($op == t('Reset to defaults')) {
        drupal_set_message(t('The configuration options have been reset to their default values.'));
      }
      else {
        if ($key = $form_state['values']['extendy_key']) {
          unset($form_state['values']['extendy_campaign_id'], $form_state['values']['extendy_campaign_name']);
          $details = extendy_query_details($key);
          if (is_array($details)) {
            variable_set('extendy_campaign_id', $details['id']);
            variable_set('extendy_campaign_name', $details['name']);
            drupal_set_message(t('Good news! The Campaign ID (' . $details['id'] . ') and Campaign Name (' . $details['name'] . ') were retrieved and updated!'), 'status');
          }
          else {
            drupal_set_message(t('Something went horribly wrong. Was that the right API Key? The Extendy module settings were not updated.'), 'warning');
          }
        }
      }
    
      cache_clear_all();
      drupal_rebuild_theme_registry();
    
    }
    

    Part of that code is already executed from the submission function added from system_settings_form().

  8.     else {
          drupal_set_message(t('Please configure the <a href="/admin/settings/extendy">Extendy module</a>.'), 'warning');
        }
    

    That message is shown to all the users, including who cannot administer the site, and change the settings as reported. Such messages should be shown only to users with the right permissions; other people don't need to know what the administer users needs to do.

  9. function extendy_install() {
    
      drupal_set_message(t('Extendy is now installed.'));
    
    }
    

    If the installation function just show a message like that, then you can remove it.

avpaderno’s picture

Status: Needs work » Closed (won't fix)

There have not been replies from the OP in the past 7 days. I am marking this report as won't fix.