How can I use a the full_html format for my custom field in my custom node type? I'd prefer a solution that didn't use any third-party modules.
I've essentially followed this guide, but my custom fields have their HTML tags escaped when rendered.
I've been searching for hours, and can't seem to quite come up with a solution.
I've added 'format' => 'full_html' like in this answer: Specifying text format when creating field on custom node type, but it didn't do anything.
After my changes I used the Devel module to uninstall and reinstall my module.
Edit: added code.
biolawnorganics_content_types.install:
<?php
require_once 'include/nodetypes.inc';
function _biolawnorganics_add_missing_fields() {
node_types_rebuild();
$nodeTypes = node_type_get_types();
$fieldInfoMap = field_info_field_map();
$fieldsArr = _biolawnorganics_build_all_fields();
$fieldsInstancesArr = $fieldsArr['instance'];
$fieldsTypesArr = $fieldsArr['type'];
foreach ($fieldsTypesArr as $ft) {
$fieldName = $ft['field_name'];
if (!isset($fieldInfoMap[$fieldName]))
field_create_field($ft);
}
$contentTypesArr = _biolawnorganics_build_all_content_types($fieldsInstancesArr);
$contentInfosArr = $contentTypesArr['info'];
$contentFieldsArr = $contentTypesArr['fields'];
foreach ($contentFieldsArr as $ck => $cfs) {
if (!isset($nodeTypes[$ck])) {
error_log("WARNING: Content type mismatch on $ck.");
continue;
}
$bodyFieldInstance = field_info_instance('node', 'field_body', $ck);
if (is_null($bodyFieldInstance))
node_add_body_field($nodeTypes[$ck]);
foreach ($cfs as $cf) {
$fieldInstance = field_info_instance('node', $cf['field_name'], $ck);
if (is_null($fieldInstance))
field_create_instance($cf);
}
}
}
function biolawnorganics_content_types_install() {
_biolawnorganics_add_missing_fields();
drupal_set_installed_schema_version('biolawnorganics_content_types', 7001);
}
function biolawnorganics_content_types_update_7001(&$sandbox) {
biolawnorganics_content_types_install();
}
function biolawnorganics_content_types_uninstall() {
$sql = 'SELECT nid FROM {node} n WHERE n.type = :type';
foreach (array_keys(_BIOLAWNORGANICS_CONTENT_TYPES) as $t) {
$result = db_query($sql, array(':type' => $t));
$nodeIds = array();
foreach ($result as $r)
array_push($nodeIds, $r->nid);
node_delete_multiple($nodeIds);
node_type_delete($t);
}
foreach (array_keys(_BIOLAWNORGANICS_FIELDS) as $f) {
$fieldInstances = field_info_instances('node', $f);
foreach ($fieldInstances as $fi)
field_delete_instance($fi);
field_delete_field($f);
}
}
// vim: set ts=2 sw=2 et syn=php:
include/nodetypes.inc:
<?php
define(
'_BIOLAWNORGANICS_FIELDS', array(
'biolawnorganics_promos' => array(
'type' => array(
'label' => 'Promotions Sidebar',
'type' => 'text_long',
'format' => 'full_html'
),
'instance' => array(
'widget' => array(
'type' => 'text_textarea',
'format' => 'full_html'
)
)
)
)
);
define(
'_BIOLAWNORGANICS_CONTENT_TYPES', array(
'biolawnorganics_home' => array(
'info' => array(
'name' => 'bioLawn Organics Home',
'description' => 'bioLawn Organics Home Page',
'has_title' => FALSE
),
'fields' => array(
'biolawnorganics_promos' => NULL
)
),
'biolawnorganics_page' => array(
'info' => array(
'name' => 'bioLawn Organics Page',
'description' => 'bioLawn Organics Generic Page',
'has_title' => TRUE,
'title_label' => 'Title'
),
'fields' => array(
'biolawnorganics_promos' => NULL
)
)
)
);
function _biolawnorganics_build_field_type($fieldName, $fieldTypePartial) {
$fieldType = $fieldTypePartial;
$t = get_t();
$fieldType['field_name'] = $fieldName;
$fieldType['label'] = $t($fieldType['label']);
return $fieldType;
}
function _biolawnorganics_build_field_instance($fieldType, $fieldInstancePartial) {
$fieldInstance = $fieldInstancePartial;
$fieldName = $fieldType['field_name'];
#$t = get_t();
$fieldInstance['field_name'] = $fieldName;
$fieldInstance['label'] = $fieldType['label'];
$fieldInstance['type'] = $fieldType['type'];
$fieldInstance['entity_type'] = 'node';
$fieldInstance['display'] = array(
'example_node_list' => array(
'label' => $fieldType['label'],
'type' => $fieldType['type']
)
);
return $fieldInstance;
}
function _biolawnorganics_build_content_info($contentName, $contentInfoPartial) {
$contentInfo = $contentInfoPartial;
$t = get_t();
$contentInfo['base'] = $contentName;
$contentInfo['name'] = $t($contentInfo['name']);
$contentInfo['description'] = $t($contentInfo['description']);
if ($contentInfo['has_title'])
$contentInfo['title_label'] = $t($contentInfo['title_label']);
return $contentInfo;
}
function _biolawnorganics_build_content_fields(
$contentName,
$contentFieldsPartial,
$fieldInstancesArr) {
$contentFields = $contentFieldsPartial;
foreach (array_keys($contentFields) as $fn) {
$fieldInstance = $fieldInstancesArr[$fn];
if (is_null($fieldInstance)) {
error_log("WARNING: Missing field instance for $fn.");
continue;
}
$fieldInstance = (array)clone (object)$fieldInstance;
$fieldInstance['bundle'] = $contentName;
$contentFields[$fn] = $fieldInstance;
}
return $contentFields;
}
function _biolawnorganics_build_all_fields() {
$fieldTypesArr = array();
$fieldInstancesArr = array();
foreach (_BIOLAWNORGANICS_FIELDS as $fk => $fv) {
$ft = _biolawnorganics_build_field_type($fk, $fv['type']);
$fi = _biolawnorganics_build_field_instance($ft, $fv['instance']);
$fieldTypesArr[$fk] = $ft;
$fieldInstancesArr[$fk] = $fi;
}
$fieldsArr = array(
'type' => $fieldTypesArr,
'instance' => $fieldInstancesArr
);
return $fieldsArr;
}
function _biolawnorganics_build_all_content_types($fieldInstancesArr) {
$contentInfosArr = array();
$contentFieldsArr = array();
foreach (_BIOLAWNORGANICS_CONTENT_TYPES as $ck => $cv) {
$ci = _biolawnorganics_build_content_info($ck, $cv['info']);
$cf = _biolawnorganics_build_content_fields($ck, $cv['fields'], $fieldInstancesArr);
$contentInfosArr[$ck] = $ci;
$contentFieldsArr[$ck] = $cf;
}
$contentTypesArr = array(
'info' => $contentInfosArr,
'fields' => $contentFieldsArr
);
return $contentTypesArr;
}
// vim: set ts=2 sw=2 et syn=php: