Home > 7 > Programmatically created content type don't have a delete link

Programmatically created content type don't have a delete link

February 12Hits:1
Advertisement

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: Programmatically created content type don't have a delete link

Answers

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.

Tags:nodes

Related Articles

  • Programmatically created content type don't have a delete link

    Programmatically created content type don't have a delete linkFebruary 12

    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',

  • Programmatically created content type module title not workingApril 8

    I created a module with a .info, .module and .install file that can be installed by customers. This module file to create content types from node consists basically atm of: /** * Implements hook_node_info() */ function mycontent_node_info() { return

  • How do you programmatically modify a programmatically created content type?December 1

    I'm creating a Drupal 7 site that has many content types which are defined programmatically. It is quite likely that, after launch, I will be required to slightly modify some of the content types. During development, whenever I need to make a change,

  • How to create content type programmatically with fields and vertical tabsFebruary 3

    I'm creating a module using Drupal7.26 and want to create content type with different type of fields like radio/checkboxes/drupdown and textfields. I'm following the last comment by Jason Gray in THIS thread and is working pretty well except it is no

  • Programmatically bind content type to Excel fileFebruary 29

    I want to create a content type (programmaticall) which can be bound to excel instead of word, and add it to a List Library so when you click create new document it opens a excel template. thanks --------------Solutions------------- You need to set t

  • create content type from workflow taskAugust 28

    I have been looking all over the internet for instructions on how to create a content type based off the Workflow Task type. Everything I have found thus far seems like it is incomplete or has gaps that I can't seem to bridge. I am using Visual Studi

  • Does Create Content Type need to be a farm solution?April 27

    I've found a couple of examples of creating a content type using visual studio. http://stevemannspath.blogspot.com/2010/11/sharepoint-2010-leveraging-visual.html http://msdn.microsoft.com/en-us/library/ff630942.aspx They both say "Deploy as Farm Solu

  • How to create content type programaticallySeptember 11

    how to create content type programatically and attach field api fields to it? hook_node_info() will not work for me since i want to create my node type and its instance in a single method (for testing purposes), so kindly suggest a solution other tha

  • creating content types with Out-of-Box vs Server Object modelsFebruary 23

    Are there any advantages in creating content type using out of box vs visual studios? --------------Solutions------------- I'm assuming that by "out of the box" you mean creating them in the User Interface. Advantages of Visual Studio Easy way t

  • How to create content type Drupal 7 October 12

    I need to add a new content type to the node/add page. How can I go about doing this? --------------Solutions------------- You should try Google before posting questions like this here. One of the first few results is the following video: Drupal 7: C

  • How to create Content Types with DrushJune 9

    Is it possible to create content types with Drush? Such as a new Galery content type? I created a content type manually via web interface and checked the changes in database. However, there are quite a lot of changes - some changes are also in blob f

  • Programatically create content type for multilingual siteNovember 13

    How to create content type for for multilingual site programatically. Example Content type column internal name: firstName. English Display Name: First Name, German Display Name:Vorname. Same for all column name and content type name. How can I do th

  • Inadvertently Created Content Type Column and now can't delete it

    Inadvertently Created Content Type Column and now can't delete itAugust 15

    I created a column on my root site's content type and now cannot delete it. It is somehow locked as "Read Only" and I have tried PowerShell and SharePoint Designer 2010 and every option I could find to no avail. This is on our top level site and

  • create Content Types like Excel,PowerPoint,One Note documents for document library in SP2013?October 14

    I want to create Content Types like Excel,PowerPoint,One Note documents for document library in SP2013,by default once enable the content type in Advance settings,we can able to see the Word content type,In site settings->site content types i can abl

  • Creating Content Type using Schema.xmlMay 24

    I am trying to create a content type from a schema.xml but the fields are not getting created, any ideas? <ContentType ID="0x0101001CC4D99118BEC246AB8D5DF12A34B61F0101" Name="License" Group="Smile" Version="3">

  • Create content type from xml using client server object modelJune 23

    I have one xml in which all the declaration of the content type are added like <ContentTypes> <!-- All Content Type Declarations --> </ContentTypes> I can't use sandbox solution for that, so I want to achieve only using client object mod

  • Create Content type with metadata fieldDecember 18

    I made the following Powershell script to create a content type with a text field and a numeric field: $url = "http://my-sharepoint-site" $web = get-spweb $url $ctypeName = "Content type X" $ctypeParent = $web.availablecontenttypes[&qu

  • How to create a new field collection+fields in a programmatically added content typeSeptember 2

    I'm very new to creating modules and I'm creating a content type for the first time programmatically. Creating the content type works fine, I've even added some fields. But now I'd like to create a new field in that content type which is a field coll

  • Add Location CCK field and instance programmatically to content type in Drupal 7May 28

    How does one add a Location CCK field and instance programmatically to a content type in a Drupal 7 module install? I am mainly concerned with what params need to be given to the field_create_field and field_create_instance functions, assuming it is

  • Create Content Type with a Default TitleMay 12

    How would for the Title of something to be default, static, unchanageable? I've got a content type (plus others planned) that I plan on using as a data submittal for stuff similar to a "Quote of the Day" or "Create an Event for the Calendar

Copyright (C) 2017 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.860 s.