Reputation: 1154
Project specification requires feature "Promote to homepage" be disabled by default. So I managed to solve it with the snippet below, but I feel like probably there is a cleaner more POO way to achieve this.
¿How can I achieve the same result without modifying a nested array key?
// Disable promote by default
function website_form_node_form_alter(&$form, FormState $form_state, $form_id)
{
switch ($form_id) {
case 'node_article_form':
if (array_key_exists('promote', $form)) {
$form['promote']['widget']['value']['#default_value'] = false;
}
break;
}
}
Upvotes: 0
Views: 1541
Reputation: 33285
I really like to code stuff, but that's not always the best solution.
Like in Drupal 7, you can also configure the promote, stick, revision default values when you edit your content type. I've attached a screenshot displaying the relevant area:
Upvotes: 1