Problem/Motivation

In some cases, default content is not created on feature activation.

Proposed resolution

  • Set the "node_content_enabled" variable to TRUE in the exported feature OR do not use this variable in defaultcontent_import_node().
  • Ensure the "default content" module is added as a dependency the exported feature.

Original report by romaingar

Hi,
I'm trying to use this module after hours trying to create a node with the "hook_enable" inside myfeatures with no success.module but even with that the default content is not created.
I've created a feature who contains only default content (with a good machine name). theses contents are nodes of simple custom types.
What's wrong ? My features contains all this files :

lvs_default_content.module
(empty)
lvs_default_content.info
core = "7.x"
description = "contenu par défault"
features[content][] = "default_page_type"
name = "lvs_default_content"
package = "Features"
php = "5.2.4"
project = "lvs_default_content"
version = "7.x-1.0-beta2"
lvs_default_content.features.content.inc
function lvs_default_content_content_defaults() {
$content = array();
$content['default_page_type'] = (object)array(
  'exported_path' => 'content/page-client-par-défault',
  'title' => 'page client par défault',
  'status' => '1',
  'promote' => '1',
  'sticky' => '0',
  'type' => 'page_client_type',
  'language' => 'fr',
  'created' => '1311782843',
  'comment' => '1',
  'translate' => '0',
  'machine_name' => 'default_page_type',
  'body' => array(
    'fr' => array(
      0 => array(
        'value' => 'ici votre texte de présentation',
        'summary' => '',
        'format' => 'filtered_html',
        'safe_value' => '<p>ici votre texte de présentation</p>
',
        'safe_summary' => '',
      ),
    ),
  ),
  'field_accroche' => array(
    'fr' => array(
      0 => array(
        'value' => 'Ici votre accroche',
        'format' => NULL,
        'safe_value' => 'Ici votre accroche',
      ),
    ),
  ),
  'field_conclusion' => array(
    'fr' => array(
      0 => array(
        'value' => 'Et là votre conclusion',
        'format' => NULL,
        'safe_value' => 'Et là votre conclusion',
      ),
    ),
  ),
);
return $content;
}

Do i have to enable defaultcontent module on my destination site ?
Is there a procedure or some dependencies for use this module ?
I've looking the code of my feature and nowhere there is an include of lvs_default_content.features.content.inc ? Is it normal ?
thanks.

CommentFileSizeAuthor
#13 node_content_enabled_true_1231302.patch411 byteskclarkson
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

romaingar’s picture

If you embed your default content with a features who create the content type of this content. it doesn't work. You have to createt 2 features. first who create content-type, seconds who create default content.

The hook "hook_content_defaults()" is called 5 times during feature installation, is it normal ?

thanks.

digitaldonkey’s picture

I have the same issue even after Splitting my module into two parts (one for the content type and one for the content).
The feature remains overridden (all content is overridden with array() ) a revert won't help.

Can I provide more information in order to get this solved?

larowlan’s picture

Hit this issue too.
Not sure which of the following sorted it:

1) Disable, uninstall and renable the affected feature

drush dis -y myfeature
drush pml-uninstall -y myfeature
drush en myfeature

2) Making sure the modules enabled on the target site matched the dev site
On dev site list enabled modules

drush pml --status=enabled --pipe|tr "\n" " "

On target site

drush en -y <paste list from other site here>

But then it worked
My bet is on 2.

netw3rker’s picture

I think there are a couple of additional issues with this too. the first is that when you export content to a feature a dependency on "defaultcontent" is not created. the second is that the new environment where the content will be being imported from wont have the "node_content_enabled" variable set. thus when the feature enables or revert is called, the content can't be created. see:

defaultcontent.module line 269:

function defaultcontent_import_node($node) {
  $plugins = defaultcontent_get_alter_plugins();
  foreach($plugins as $plugin) {
    $cb = isset($plugin['import_alter callback']) ? $plugin['import_alter callback'] : $plugin['name'] ."_import_alter";
    if (function_exists($cb)) {
      $cb($node);
    }
  }
  if(variable_get('node_content_enabled', FALSE)) {   /******** look at this line*********/
    node_save($node);
  }

a simple solution to this is to add the dependency and use strongarm for that variable when building the feature. long term, that variable should probably go since its obscure and buried in the code.

hope this helps!

RowboTony’s picture

Version: 7.x-1.0-alpha3 » 7.x-2.x-dev

Hi, I've been experimenting with this module for a couple of hours and I am not at all understanding how to make it work... here's what I done.

* I download and enable the defaultcontent module
* add machine names to the nodes I wish to export with defaultcontent
* go to Create Feature
* check the boxes for those nodes while creating a feature
* select the nodes I want from Content Item: content
* download feature
* untar feature on a different site
* no content is created

I've tried adding defaultcontent as a module dependency and a few other things, but I'm just poking around in the dark - can someone kindly explain what I'm not doing right? Or document the simplest use case of exporting a few nodes as defaultcontent?

I only started playing with this module when I couldn't get the OpenPublic Demo content to work on another site - I dropped "openpublic_demo_content" in another site, enabled it and no content was enabled, I'm obviously missing something here with this feature/Features use case. I know too there's a devel-generate module, but that's not what I need, I just need a few simple pages with my own pre-filled (non-ipsum) content to export for most every site I build: About, Contact, Service, FAQ, etc. I thought it should be simple with this module, but not so much, any guidance is greatly appreciated.

Thank you,
--Tony

rvilar’s picture

Version: 7.x-2.x-dev » 7.x-1.x-dev

Tony, 7.x-2.x-dev branch it's a non funtional branch that it's in a heavy development process to integrate with UUID. Please, use 7.x-1.x branch in a production project.

nick_schuch’s picture

In regards to comment #3 and #5.

I ran into the exact same issue when testing between to sites. I discovered that I did not have the uuid module install onto site number 2 (uuid is a dependancy of defaultcontent module).

Might be worth making both defaultcontent and uuid modules as dependancies of your defaultcontent module.

jide’s picture

#4 from @netw3rker is the right answer.

To make it clear and simple :

- Set the "node_content_enabled" variable to TRUE.
- Ensure the "default content" module is enabled (or a dependency of your feature).

jide’s picture

Title: Default content not created... » Default content not created in some cases
Component: Documentation » Code
Category: support » bug
Priority: Normal » Major

Let's set this as a bug. I also added an issue summary. Bumping to major.

kclarkson’s picture

I was able to get it working after by downloading the 7.x-1x version and following the instructions from #4 and #8.

Can this be added as a patch seeming it works by changing it to TRUE ?

frankcarey’s picture

Issue tags: +wtf

I tried to dig in and fix this, but I don't understand why the developer wrote it in such an odd way. It looks like the order that needs to happen without patching the module, or setting the variable manually is like so:

1) Enable defaultcontent
2) Run cron, which ends up using a non-api parameter in defaultcontent_cron($allow_first_content = TRUE). Because core cron doesn't set a parameter, it defaults to be true, which then does:

if ($allow_first_content) {
  variable_set('node_content_enabled', TRUE);
}

// ... Import content

3) If your module was already enabled at this point, the content should be imported when that cron was run. If not, you can enable it now.. and then the defaultcontent_modules_enabled($modules) hook runs, which runs defaultcontent_cron(FALSE) (note the false here) , and then since node_content_enabled is already set to TRUE (see #2) then the imports will also happen.

We really kind of need to hear from the developers why such a convoluted path was taken to know how to fix this.. I already see a couple issues with this method beyond the fact that when you enable your module, you expect the content to be created, which doesn't happen unless you run defaultcontent_cron(TRUE) first like in your hook_install().

A) Every cron run, this module is doing a lot of stuff, including a variable_set .. over and over for no reason.
B) Everytime any module is enabled, this module does a bunch of stuff.
C) When a defaultcontent export module is enabled, this module does a bunch of stuff, just doesn't save the node at the end of the process.

Whoever worked on this could do us a real solid and provide more code documentation and some explanations as to why they went this direction. It seems like we should just cut out all the cron business, or at least use a queue process that then runs on cron for imports that are too much to handle on one call. I also see no reason to do all this checking on every cron run. It should import the content one time only, and only check when checking a feature's status.

autopoietic’s picture

#11 solved my problem. I couldn't see the node_content_enabled variable until I ran cron, then all the content I was expecting just popped up. Thanks Frank

kclarkson’s picture

Status: Active » Needs review
FileSize
411 bytes

I know this is something simple but I wanted to create a patch just so that I remembered.

Credit goes out to @netw3rker for fixing this.

This patch just changes line 299 to TRUE.

Lets get someone to commit this so that we all don't have to patch this for a new install.

Thanks,

Jeffrey C.’s picture

Hello there,

Can anyone confirm #13 fixes the issue?

Jeffrey C.’s picture

Meanwhile, please take a minute to check out #1869366: Future Plan.

mrfelton’s picture

The patch in 13 does work to ensure that default content gets properly crated when a default content module is enabled, and doesn't rely on cron having been run first - which is often not the case in an installation profile.

The question still stands though as to why this module doing so much stuff on cron run. Why does it force cron to be run every time a module is enabled?

mrfelton’s picture

Issue summary: View changes

Change the issue to an issue summary.