To make it easy for modules to integrate with Key, the version of the module for Drupal 7 adds a new form API element called key. It extends the select element, but fills #options with the list of available keys. It also provides additional instructions for using and defining keys in the #description. Here's an example of what that looks like in code:

$form['secret_key'] = array(
  '#type' => 'key',
  '#title' => t('Secret key'),
);
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rlhawk created an issue. See original summary.

rlhawk’s picture

It probably makes sense to call this "key_select", just to be specific and because later on we may want to add other form elements, such as one that displays available keys as radios, or as a text field with autocomplete.

rlhawk’s picture

Here's a patch that adds a basic version of the key_select element. It extends the select form element, but uses the keys as options. It also allows the element to include information about keys to the description. The #filters property is defined, but has no effect yet.

rlhawk’s picture

Assigned: Unassigned » rlhawk
tynor’s picture

rlhawk’s picture

Status: Needs review » Reviewed & tested by the community

Looks good.

  • rlhawk committed c2b9531 on 8.x-1.x
    Issue #2624690 by rlhawk, tynor: Create new Key Form API element
    
rlhawk’s picture

Status: Reviewed & tested by the community » Fixed

The last submitted patch, 3: create_new_key_form_api-2624690-3.patch, failed testing.

Status: Fixed » Closed (fixed)

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