Problem/Motivation

Today Scrambler has no integration to export the settings through the Features module.

Proposed resolution

Use ctools to enable this integration.

Remaining tasks

  • New column needed field_name in scrambler_field table.
  • Add ctools as dependency.
  • Use ctools as export api in hook_schema().
  • Write upgrade path with hook_update_N().

User interface changes

  • Add column field id to the administrative View.
  • Change column field name to the administrative View.

API changes

None.

Data model changes

Open question: should field id still be the primary key or can we work with the field's machine name?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Novitsh created an issue. See original summary.

Novitsh’s picture

Novitsh’s picture

Status: Active » Needs review
beerendlauwers’s picture

  1. +++ b/modules/scrambler_field/includes/scrambler_field.view.inc
    @@ -87,8 +95,8 @@ function scrambler_field_preprocess_views_view_table(array &$vars) {
    +    if ($row['field_machine_name'] != 0) {
    

    Why are you checking against a 0 ? Perhaps the empty string or using isset would be better ?

  2. +++ b/modules/scrambler_field/scrambler_field.install
    @@ -29,3 +47,44 @@ function scrambler_field_schema() {
    +        'field_name' => $field->fid === '-1' ? 'title' : $field_info[$field->fid],
    

    Perhaps add a comment here why you do the -1 check?

Novitsh’s picture

Assigned: Novitsh » Unassigned
FileSize
7.25 KB

Updated version attached, thanks for the feedback!

tim@lammar.be’s picture

Originally your schema had 1 field (fid), now you are adding field_name.
You want to automatically add the machine name of each field already in this table, right?
In that case, instead of using an update hook inside a foreach loop, I would use a bulk delete/insert instead. (this action affects all the records anyway)
You already start by doing a select to get all fids.
Next i would truncate the whole table.
Next, based on your $fid array, you can build a bulk insert hook.
Something like:


$configured_fields = db_select('scrambler_field', 'sf')
      ->fields('sf', array('fid'))
      ->execute()
      ->fetchAll();

db_truncate('scrambler_field')->execute();
// Update all fields to work with the field machine name instead of an id.
$insert_query = db_insert('scrambler_field')->fields(array('fid', 'field_name'));
foreach ($configured_fields as $field) {
  $insert_query->values = array(
    'fid' => $field->fid,
    'field_name' => $field->fid === '-1' ? 'title' : $field_info[$field->fid],
  );
}
$insert_query->execute();
tim@lammar.be’s picture

Hereby the patch file of my previous comment.

nico.knaepen’s picture

There is no specific reason why I started by using field id instead of the field machine name. It's just my way of working for all kind of relations in tables. So I don't see an issue to switch to the field machine name.

  • Novitsh committed 3d4fd90 on 7.x-1.x
    Issue #2946359 by Novitsh, beerendlauwers, Tim Lammar: Add support for...
Novitsh’s picture

Status: Needs review » Fixed

Thx all for the testing. Commited.

Status: Fixed » Closed (fixed)

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