Best practice: content types with unique machine names We have a module install script that auto-generates content types.

The content type machine names are based on text field data inputted by a user using a custom form. For example:

User title = 'Technical' => Auto-generated machine name = technical_comp

User title = 'Specialist Claims' => Auto-generated machine name = specialist_claims_comp

… and so on.

For the module to be robust, it needs to create unique 32 character machine names where there are two text fields with the same data.

Is there best practice around this?

I was thinking something along the lines of:

User title = Technical => Auto-generated machine name = a1_comp

User title = Specialist Claims => Auto-generated machine name = a2_comp

… which would give us plenty of scope but would require some kind of content type count.
Counting content types should be as easy as:

$result = db_select('node_type')
        -&gt;fields('node_type')
        -&gt;execute();
$num_of_results = $result-&gt;rowCount();


https://www.drupal.org/node/1226410