0

I'm developing a module that creates new content types through form that I created (not in hook_install):

function create_new_content_type($type, $name){
    $t = get_t();

    $new_node = array(
        'type' => $type,
        'name' => $name,
        'base' => 'node_content',
        //'description' => 'This is an example node type with a few fields.',
    );
    $content_type = node_type_set_defaults($new_node);
    node_add_body_field($content_type);

    // Check if we create content type or update.
    $status = node_type_save($content_type);

    // Replacement rule for the messages.
    $t_args = array('%name' => $content_type->name);

    if ($status == SAVED_NEW) { // create case
        watchdog('node', 'Added content type %name.', $t_args, WATCHDOG_NOTICE, l($t('view'), 'admin/structure/types'));
        return true;
    }

    return false;
}

When I go to admin/structure/types these I don't see the delete link.
I found here some similar questions that suggest to remove with /admin/structure/types/manage/<content-type-name>/delete but it's not a good solution for me.
Is it possible to display that link?

EDIT: This is what I mean: enter image description here

1
  • 2
    This is a known issue in Drupal core. And currently there's no fix to it apart from appending /delete at the end of the url. Why is it not a good solution for you? Do you not have a listing page of some sort that lists the content types you created through this form? Then if not, maybe create one, and manually create the links with /delete at the end.
    – Beebee
    Commented Feb 12, 2014 at 13:54

1 Answer 1

1

You could always take the dull axe approach and use a page_alter, eg, something along the lines of

function YOURMODULE_page_alter(&$page) {

  if ($_GET['q']=='admin/structure/types') {

    $page['content']['system_main']['node_table']['#rows'][]=array(
      'Foo <small>(Machine name: foo)</small><div class="description">Here is my description of foo</div>',
      array('data' => l(t('edit'), 'admin/structure/types/manage/foo')),
      array('data' => l(t('manage fields'), 'admin/structure/types/manage/foo/fields')),
      array('data' => l(t('manage display'), 'admin/structure/types/manage/foo/display')),
      array('data' => l(t('delete'), 'admin/structure/types/manage/foo/delete')),
    );

  }

}

which will create a row for type foo.

Per additions to the question: since the row is showing up but just without the delete link, you can go in and create it similarly, eg,

$page['content']['system_main']['node_table']['#rows'][NUM][4]=array('data' => l('delete', 'admin/structure/types/manage/foo/delete'));

where NUM is the row number where your content type is found. You might also want to check out Adding an operation to Content Types and the page_alter() there on a possible way you might be able to easily figure out NUM.

Another addition:

Could you just do this in your module:

$info = array(
    'type' => $type,
    'name' => $name,
    'base' => 'node_content',
    'custom' => TRUE, // fake it out to think it was made via the UI...
);
$content_type = node_type_set_defaults($info);

A cursory glance through the code and node_type_set_defaults() suggests that the only thing this does is allow this delete link to be presented in this very form.

3
  • I added a screenshot. Is that more clear?
    – NickF
    Commented Feb 13, 2014 at 7:54
  • Sure, you can "add in" the delete link via the second method mentioned in my answer above.
    – Jimajamma
    Commented Feb 13, 2014 at 7:59
  • The 'custom' => TRUE, worked
    – NickF
    Commented Feb 16, 2014 at 12:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.