Attached is a patch that would add several new components:

1) Sequences

2) Storage

Sequences work like this: they replace some given text with a number given by a function. The sequence component itself keeps track of the numbereth time in the sequence: starting at 0, going up by one each time. It then passes that number into a function selected by the user, which had been previously registered through an implementation of hook_flexifilter_sequences. Included in this are basic numbers, lower case letters, and upper case letters.

There are two storage components, a set and a get. The set component sets one variable slot to the current text as run through a set of components set in the settings. The get component gets the variable set previously in one of the variable slots, runs it through a set of components set in the settings, and returns it.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

corsix’s picture

Status: Needs review » Needs work

I don't think you totally understand static variables:

 +function flexifilter_component_storage_set($op, $settings, $text) {
+  switch ($op) {
+    case 'settings':
+      return flexifilter_storage_slot();
+
+    case 'prepare':
+    case 'process':
+      $data = flexifilter_invoke_components($settings['components'], $op, $text);
+	  static $_flexifilter_stored_data = array(); 
 +function flexifilter_component_storage_get($op, $settings, $text) {
+  switch ($op) {
+    case 'settings':
+      $form = flexifilter_storage_slot();
+
+    case 'prepare':
+    case 'process':
+      static $_flexifilter_stored_data = array(); 

Static variables are just like local variables, only they are persistent across calls to the function. Giving static variables within two different functions the same name does not cause them to be the same variable. Hence, doing a storage get will always be blank, as the storage set was stored in a different variable.

cwgordon7’s picture

Sequences committed; storage needs work.

apaderno’s picture

It's enough to change the code to:

function flexifilter_component_storage_set($op, $settings, $text) {
  switch ($op) {
    case 'settings':
      return flexifilter_storage_slot();

    case 'prepare':
    case 'process':
      $data = flexifilter_invoke_components($settings['components'], $op, $text);
      $stored_data = flexifilter_get_stored_data();
      $stored_data[$settings['slot']] = $data;
      return $text;
  }
}

/**
 * Component callback.
 */
function flexifilter_component_storage_get($op, $settings, $text) {
  switch ($op) {
    case 'settings':
      $form = flexifilter_storage_slot();

    case 'prepare':
    case 'process':
      $stored_data = flexifilter_get_stored_data();
      if (!isset($stored_data[$settings['slot']])) {
        $stored_data[$settings['slot']] = '';
      }
      $data = flexifilter_invoke_components($settings['components'], $op, $_flexifilter_stored_data[$settings['slot']]);
      return $data;
  }
}

function &flexifilter_get_stored_data() {
  static $data;
  
  return $data;
}
kenorb’s picture

Assigned: cwgordon7 » Unassigned
kenorb’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)

Drupal 6 is no longer officially supported. If you think this issue is still relevant for 8.x, feel free to re-open.