Currently this field is only a hidden field.
When this possibility is implemented the sitebuilders can still decide to hide this field.

Comments

kehan’s picture

And that's why it doesn't show up in a view or an Automatic Entity Label
+1 for this feature.

kehan’s picture

And to do this add the following to machine_name.module


/**
 * Implements hook_field_formatter_info()
 */
function machine_name_field_formatter_info(){
	return array(
			'machine_name_default' => array(
					'label' => t('Default'),
					'field types' => array('machine_name')));
}

/**
 * Implements hook_field_formatter_view().
 */
function machine_name_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
	$element = array();
	switch($display['type']){
		case 'machine_name_default':
			// Taken from text.module
			foreach ($items as $delta => $item) {
				$element[$delta] = array('#markup' => strip_tags($item['value']));
			}
			break;
	}
	return $element;
}
c-logemann’s picture

Status: Active » Needs review

Thank you kehan for your help.
I set status to "needs review".

I will check this by myself when I have time to.

If you want to do more you can create a patch to make testing easier especially for automated tests:
http://drupal.org/node/332678

kehan’s picture

I'll work on a patch when I'm on this again later this week. A much simpler workaround is using hook_field_formatter_info_alter to simply associate text_plain with 'machine_name' field types.

function MODULE_NAME_field_formatter_info_alter(&$info){
        if(!array_search('machine_name', $info['text_plain']['field types'])){
                $info['text_plain']['field types'][] = 'machine_name';
        }
}

bdragon’s picture

c-logemann’s picture

Assigned: Unassigned » c-logemann

Ok, I try to work on this on this weekend.

c-logemann’s picture

Status: Needs review » Needs work

After working on #1578454: Undefined index: machine_name_machine_name the code of #2 doesn't work anymore.
I am still working on this problem.

c-logemann’s picture

Status: Needs work » Closed (fixed)

I don't know where the problem was but I now it's working well. I've successfully tested the upgrading several times.
There was only a problem with upgrading from alpha version to current code and the new formatter won't appear on "manage display" only on fresh install. Maybe a kind of caching problem with fields? Feel free to reopen this issue if someone have problems like this.

I've cleaned the code of #2 a little bit and committed it:
http://drupalcode.org/project/machine_name.git/commit/e0da251

rogerrogers’s picture

Hi, I've upgraded to the dev version so that I can use this field formatter to render the machine name field. However, the formatter doesn't display, I assume because I already have the machine_name module installed before changing to the --dev version. I don't want to uninstall, because I will lose the machine name fields I've already setup. Is there a way to manually update the database to add the field formatter info?

For now I've added this snippit to the machine name module:

function machine_name_field_formatter_info_alter(&$info){
        if(!array_search('machine_name', $info['text_plain']['field types'])){
                $info['text_plain']['field types'][] = 'machine_name';
        }
}

However, I'm concerned that if the module ever gets updated this will be replaced and the field won't render. So, would like to get this sorted properly, since the dev version does register this formatter on install.

Cheers!

c-logemann’s picture

Issue summary: View changes

@RogerRogers: I opened a new Issue to answer your questions.
To show it's related to this issue, I connected it: #2822623: field formatter doesn't work properly