0

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.

2
  • Are you using unique fields in each content_type? Just wondering what the purpose of this approach is.
    – dibs
    Commented Feb 22, 2015 at 22:26
  • @dibs It's because it's likely we may have two instances where the first 27 chars are the same (32 - '_comp' suffix). Commented Feb 23, 2015 at 8:38

1 Answer 1

1

Counting content types should be as easy as:

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

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

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.