From 240b9d0e488f52e2d520693b3ea7be49457fdcc3 Mon Sep 17 00:00:00 2001 From: James Silver Date: Fri, 19 Oct 2012 13:38:45 +0100 Subject: [PATCH] Issue #1817620 by jamsilver: Added support for entity module's property info api. --- metatag.module | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 65 insertions(+), 0 deletions(-) diff --git a/metatag.module b/metatag.module index 4cfe352..35893b1 100644 --- a/metatag.module +++ b/metatag.module @@ -776,6 +776,71 @@ function metatag_entity_info_alter(&$info) { } /** + * Implements hook_entity_property_info_alter(). + */ +function metatag_entity_property_info_alter(&$entity_info) { + $info = array(); + + $properties = &$info['node']['properties']; + + // Describe our metatags property on any entity type. + $properties['metatags'] = array( + 'label' => t("Metatags"), + 'description' => t("Meta-data about a node which is consumed and displayed by search engines."), + 'getter callback' => 'metatags_entity_metadata_get_properties', + 'setter callback' => 'entity_property_verbatim_set', + 'auto creation' => 'entity_property_create_array', + 'type' => 'struct', + 'property info' => array( + 'title' => array( + 'label' => t("Title"), + 'description' => t("A comma-separated list of keywords about the page. This meta tag is not supported by most search engines."), + 'getter callback' => 'metatags_entity_metadata_get_properties', + 'setter callback' => 'metatags_entity_metadata_set_properties', + 'type' => 'text', + ), + 'description' => array( + 'label' => t("Description"), + 'description' => t("A comma-separated list of keywords about the page. This meta tag is not supported by most search engines."), + 'getter callback' => 'metatags_entity_metadata_get_properties', + 'setter callback' => 'metatags_entity_metadata_set_properties', + 'type' => 'text', + ), + 'keywords' => array( + 'label' => t("Keywords"), + 'description' => t("A comma-separated list of keywords about the page. This meta tag is not supported by most search engines."), + 'getter callback' => 'metatags_entity_metadata_get_properties', + 'setter callback' => 'metatags_entity_metadata_set_properties', + 'type' => 'text', + ), + ), + ); + + return $info; +} + +/** + * Gets the property from the given data. Entity metadata getter callback. + */ +function metatags_entity_metadata_get_properties($data = FALSE, array $options, $name) { + switch ($name) { + case 'metatags': + return !empty($data->metatags) ? $data->metatags : array(); + default: + return isset($data[$name]['value']) ? $data[$name]['value'] : ''; + } +} + +/** + * Sets the property to the given value. Entity metadata setter callback. + */ +function metatags_entity_metadata_set_properties(&$data, $name, $value, $langcode, $type, $info) { + $data[$name] = array( + 'value' => $value, + ); +} + +/** * Given a path determine if it is an entity default path. * * @param $path -- 1.7.1