Are there any automatic fields value generation from node body F.E.?

Comments

valthebald’s picture

Assigned: Unassigned » valthebald

Not yet. Any idea of how do you see it?

podarok’s picture

job_queue i think...
after node creating make it as background task via job_queue and auto-filling via cron

valthebald’s picture

The question here is not HOW to fill meta fields (IMO the best way is to react to node insert/update), but WHAT values to use.
Obviously, it is impossible and meaningless to copy body or any other field into meta, so - how do you specify pattern for description/keywords?

robcarr’s picture

Can't tokens be used? That's how the D6 Nodewords module worked (didn't it?).

valthebald’s picture

Makes sense.
Probably token usage will not require any code change :)
I will check that.

valthebald’s picture

Status: Active » Postponed

Regretfully, field subsystem of D7 does not support tokens "natively" (see broad discussion at http://drupal.org/node/691078). There are some workarounds, please read discussion.
I postpone this issue until we have some solution in core token or token contrib.
Correct me if I'm wrong, but currently I don't see any other option :(

POVYLAZZZ’s picture

Maybe you could give some hints how to set them programaticly?

valthebald’s picture

I'm afraid that I don't understand your question.
Little bit more details please?

POVYLAZZZ’s picture

Sorry I meant field values.
I guess I could make use of function which check`s if field is empty. And write a switch based on field name. Inside switch I would put something like that:
$node->field_y[$node->language][0]['value'] = $node->field_x[$node->language][0]['value'];
Does the node_save function is necessary after it? And how to get for example term names? The $node->terms contains only an array of term id`s and I need names.

valthebald’s picture

Easy way to achieve this (no programming): declare field as required, set it's default value - in any new page you will have values prepopulated!

valthebald’s picture

Version: 7.x-1.0-beta4 » 7.x-1.x-dev
Johnny vd Laar’s picture

I've done this via Rules:

{ "rules_auto_save_meta_tag_description" : {
    "LABEL" : "Auto save meta tag description",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules" ],
    "ON" : [ "node_presave" ],
    "IF" : [
      { "node_is_of_type" : { "node" : [ "node" ], "type" : { "value" : { "page" : "page" } } } },
      { "data_is_empty" : { "data" : [ "node:field-description" ] } }
    ],
    "DO" : [
      { "data_set" : { "data" : [ "node:field-description" ], "value" : "[node:summary]" } }
    ]
  }
}

The problem is that the summary field should not contain too much data

Johnny vd Laar’s picture

Ok I modified it such that it creates a truncated version with tags stripped:

{ "rules_auto_save_meta_tag_description" : {
    "LABEL" : "Auto save meta tag description",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "php" ],
    "ON" : [ "node_presave" ],
    "IF" : [
      { "node_is_of_type" : { "node" : [ "node" ], "type" : { "value" : { "page" : "page" } } } },
      { "data_is_empty" : { "data" : [ "node:field-description" ] } }
    ],
    "DO" : [
      { "data_set" : {
          "data" : [ "node:field-description" ],
          "value" : "\u003c?php print truncate_utf8(strip_tags($node-\u003ebody['und'][0]['summary']), 255); ?\u003e"
        }
      }
    ]
  }
}
andypost’s picture

Status: Postponed » Needs review

I think the module's schema should be extended with small int field use_defaults!

So each entity get a record of meta-field, this approach gives ability to reflect on changing default values without updating data in DB.

Default values could be customized within field settings on instance level

EDIT: Another way is to extent hook_field_is_empty() to report each time that field is not empty

valthebald’s picture

Status: Needs review » Needs work

More correct status is 'needs work' I guess :)
You have only suggestion, not a ready patch...

andypost’s picture

Sure, I'll try to test this on holidays

valthebald’s picture

Status: Needs work » Closed (duplicate)

From now on, please post comments on autofill in #1122486: Support for tokens in field values