Skip to content

Instantly share code, notes, and snippets.

@piyuesh23
Created October 12, 2015 07:11
Show Gist options
  • Save piyuesh23/e8c010f1ea8238c6b9e5 to your computer and use it in GitHub Desktop.
Save piyuesh23/e8c010f1ea8238c6b9e5 to your computer and use it in GitHub Desktop.
Only in /Users/piyuesh23/htdocs/acquia/opera/sites/all/modules/user/entity_email/: entity_email.admin.inc.patch
Only in /Users/piyuesh23/htdocs/acquia/opera/sites/all/modules/user/entity_email/: entity_email.entity_email_type.inc.patch
diff -uprb a/entity_email.info b/entity_email.info
--- entity_email.info 2013-11-04 17:21:33.000000000 +0530
+++ entity_email.info 2015-01-14 12:46:34.000000000 +0530
@@ -2,6 +2,8 @@ name = Entity Email
description = Entity Email.
dependencies[] = entity_token
dependencies[] = entity
+dependencies[] = entity_translation
+dependencies[] = entity_translation_i18n_menu
core = 7.x
package = Mail
@@ -9,7 +11,7 @@ package = Mail
files[] = entity_email.info.inc
files[] = includes/entity_email.entity_email_type.inc
files[] = includes/entity_email.entity_email.inc
-
+files[] = includes/translation.handler.entity_email_type.inc
files[] = entity_email.test
; Views
diff -uprb a/entity_email.install b/entity_email.install
--- entity_email.install 2013-11-04 15:05:56.000000000 +0530
+++ entity_email.install 2015-01-14 12:46:34.000000000 +0530
@@ -10,6 +10,20 @@
*/
function entity_email_install() {
$t = get_t();
+ // Create the field holding the mail subject.
+ $field = array(
+ 'field_name' => ENTITY_EMAIL_FIELD_MAIL_SUBJECT,
+ 'type' => 'text',
+ 'entity_types' => array('entity_email_type'),
+ 'cardinality' => 1,
+ 'translatable' => TRUE,
+ 'locked' => TRUE,
+ 'settings' => array(
+ // Mark that this field can be rendered using EntityEmail::getMailSubject().
+ 'entity_email_text' => TRUE,
+ ),
+ );
+ $field = field_create_field($field);
// Create the field holding the mail body.
$field = array(
'field_name' => ENTITY_EMAIL_FIELD_MAIL_BODY,
@@ -55,6 +69,19 @@ function entity_email_install() {
);
$field = field_create_field($field);
+ // Create an instance of the mail Subject field.
+ $instance = array(
+ 'field_name' => ENTITY_EMAIL_FIELD_MAIL_SUBJECT,
+ 'bundle' => 'entity_email_type',
+ 'entity_type' => 'entity_email_type',
+ 'label' => $t('Mail subject'),
+ 'description' => $t('The mail subject of the email template.'),
+ 'required' => FALSE,
+ 'settings' => array(
+ //'text_processing' => 1,
+ ),
+ );
+ field_create_instance($instance);
// Create an instance of the mail body plain field.
$instance = array(
'field_name' => ENTITY_EMAIL_FIELD_MAIL_BODY_PLAIN,
@@ -103,6 +130,8 @@ function entity_email_install() {
*/
function entity_email_uninstall() {
// Delete all instances.
+ $instance = field_info_instance('entity_email_type', 'entity_email_mail_subject', 'entity_email_type');
+ field_delete_instance($instance);
$instance = field_info_instance('entity_email_type', 'entity_email_mail_body', 'entity_email_type');
field_delete_instance($instance);
$instance = field_info_instance('entity_email_type', 'entity_email_mail_body_plain', 'entity_email_type');
@@ -110,6 +139,7 @@ function entity_email_uninstall() {
$instance = field_info_instance('entity_email_type', 'entity_email_mail_attachment', 'entity_email_type');
field_delete_instance($instance);
// Delete all fields.
+ field_delete_field('entity_email_mail_subject');
field_delete_field('entity_email_mail_body');
field_delete_field('entity_email_mail_body_plain');
field_delete_field('entity_email_mail_attachment');
@@ -158,13 +188,6 @@ function entity_email_schema() {
'length' => 255,
'not null' => FALSE,
),
- 'subject' => array(
- 'description' => 'The template email subject.',
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '',
- ),
'created' => array(
'description' => 'When the email template was created.',
'type' => 'int',
@@ -179,6 +202,12 @@ function entity_email_schema() {
'unsigned' => TRUE,
'default' => 0,
),
+ 'template_fpid' => array(
+ 'description' => 'Store fieldable panel id (fpid)',
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => FALSE,
+ )
),
'unique keys' => array(
'name' => array('name'),
@@ -289,3 +318,19 @@ function entity_email_schema() {
return $schema;
}
+
+/**
+ * Patch by Alin.
+ * Add new field in entity email to store the template type
+ */
+function entity_email_update_7200() {
+ $schema = array(
+ 'description' => 'Store fieldable panel id (fpid)',
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => FALSE,
+ );
+ if (!db_field_exists('entity_email_type', 'template_fpid')) {
+ db_add_field('entity_email_type', 'template_fpid', $schema);
+ }
+}
Only in /Users/piyuesh23/htdocs/acquia/opera/sites/all/modules/user/entity_email/: entity_email.install.patch
diff -uprb a/entity_email.module b/entity_email.module
--- entity_email.module 2013-11-04 15:05:56.000000000 +0530
+++ entity_email.module 2015-06-16 21:32:10.000000000 +0530
@@ -8,6 +8,7 @@
/**
* Define a couple of realm fields.
*/
+define('ENTITY_EMAIL_FIELD_MAIL_SUBJECT', 'entity_email_mail_subject');
define('ENTITY_EMAIL_FIELD_MAIL_BODY', 'entity_email_mail_body');
define('ENTITY_EMAIL_FIELD_MAIL_BODY_PLAIN', 'entity_email_mail_body_plain');
define('ENTITY_EMAIL_FIELD_MAIL_ATTACHEMENT', 'entity_email_mail_attachment');
@@ -53,6 +54,15 @@ function entity_email_entity_info() {
'file' => 'includes/entity_email.admin.inc',
'controller class' => 'EntityEmailTypeUIController',
),
+ 'translation' => array(
+ 'entity_translation' => array(
+ 'class' => 'EntityTranslationEntityEmailTypeHandler',
+ 'base path' => 'admin/structure/entity_email_type/manage/%entity_email_type',
+ 'edit path' => 'admin/structure/entity_email_type/manage/%entity_email_type/edit',
+ //'edit form' => 'entity_email_type',
+ 'edit tabs' => TRUE,
+ ),
+ ),
),
);
$items['entity_email'] = array(
@@ -79,6 +89,10 @@ function entity_email_entity_info() {
return $items;
}
+function entity_email_form_entity_email_type_form_alter(&$form, &$form_state, $form_id) {
+ $form['#entity_type'] = 'entity_email_type';
+}
+
/**
* Implements hook_views_api().
*/
@@ -132,6 +146,15 @@ function entity_email_entity_property_in
'query callback' => 'entity_metadata_table_query',
'schema field' => 'updated',
);
+ //patch by alin
+ $properties['template_fpid'] = array(
+ 'label' => t("Template"),
+ 'type' => 'int',
+ 'schema field' => 'template_fpid',
+ 'setter callback' => 'entity_property_verbatim_set',
+ 'query callback' => 'entity_metadata_table_query',
+ );
+
// Add meta-data about the basic entity_email properties.
$properties = &$info['entity_email']['properties'];
$properties['eid'] = array(
@@ -273,6 +296,8 @@ function entity_email_theme() {
'render element' => 'elements',
'template' => 'entity_email',
);
+
+
return $info;
}
@@ -362,6 +387,10 @@ function entity_email_type_delete_multip
function entity_email_type_load($name = NULL) {
// Replace dashes with underscores so this can be used as menu argument
// loader too.
+ if(is_numeric($name)) { //id is passed
+ $types = entity_email_type_load_multiple(array($name));
+ return isset($types[$name]) ? $types[$name] : FALSE;
+ }
$types = entity_load_multiple_by_name('entity_email_type', isset($name) ? array(strtr($name, array('-' => '_'))) : FALSE);
if (isset($name)) {
return isset($types[$name]) ? $types[$name] : FALSE;
@@ -412,7 +441,9 @@ function entity_email_create($type, $val
return NULL;
}
- // Current user.
+ $entity = entity_email_type_load($type);
+
+// Current user.
$values['cuid'] = (int) $user->uid;
// Entity type.
@@ -436,7 +467,23 @@ function entity_email_create($type, $val
$values['nid'] = (isset($values['nid'])) ? $values['nid'] : NULL;
- return entity_create('entity_email', $values);
+ $values['webform_data'] = (isset($values['webform_data'])) ? $values['webform_data'] : NULL;
+
+ $new_entity=entity_create('entity_email', $values);
+
+ if(!empty($values['template_fpid'])) {
+ $new_entity->template_fpid = $values['template_fpid'];
+ }
+
+ /*
+ global $language;
+ $new_entity->subject = $entity->entity_email_mail_subject[$language->language][0]['value'];
+ $new_entity->mail_body = $entity->entity_email_mail_body[$language->language][0]['value'];
+ $new_entity->mail_body_plain = $entity->entity_email_mail_body_plain[$language->language][0]['value'];
+ //end hack
+ */
+
+ return $new_entity;
}
/**
@@ -465,7 +512,8 @@ function entity_email_send($entity_email
// If mailto is not valid.
if (!valid_email_address($entity->mail_to)) {
- watchdog('entity_email', 'Could not send the email entity as the mailto was not correct', $entity->mail_to, WATCHDOG_ERROR);
+ //fixed by alin, third param must be array
+ watchdog('entity_email', 'Could not send the email entity as the mailto was not correct: @mailTo', array('@mailTo' => '-'.$entity->mail_to.'-'), WATCHDOG_ERROR);
return NULL;
}
@@ -562,5 +610,9 @@ function entity_email_substitutions($par
$substitutions['current-user'] = user_load($user->uid);
}
+ if(!empty($params['webform_data'])) {
+ $substitutions['webform'] = $params['webform_data'];
+ }
+
return $substitutions;
}
Only in /Users/piyuesh23/htdocs/acquia/opera/sites/all/modules/user/entity_email/: entity_email.module.patch
diff -uprb a/entity_email.rules.inc b/entity_email.rules.inc
--- entity_email.rules.inc 2013-11-04 15:05:56.000000000 +0530
+++ entity_email.rules.inc 2015-01-14 12:46:36.000000000 +0530
@@ -59,6 +59,11 @@ function entity_email_rules_action_info(
'description' => t("Leave it empty to use the site-wide configured address."),
'optional' => TRUE,
),
+ 'webform_data' => array(
+ 'type' => 'webform',
+ 'label' => 'Webform data',
+ 'optional' => TRUE,
+ ),
'entity-email-save' => array(
'type' => 'boolean',
'label' => t("Save Email"),
@@ -74,7 +79,7 @@ function entity_email_rules_action_info(
/**
* Callback for anonymous rules action.
*/
-function entity_email_rules_send_message($entity_email_name, $entity_email_from, $entity_email_to, $entity_email_node, $entity_email_mailto, $entity_email_mailfrom, $entity_email_replyto, $entity_email_save) {
+function entity_email_rules_send_message($entity_email_name, $entity_email_from, $entity_email_to, $entity_email_node, $entity_email_mailto, $entity_email_mailfrom, $entity_email_replyto, $webform_data, $entity_email_save) {
$params = array(
'fuid' => isset($entity_email_from) ? $entity_email_from->uid : NULL,
'tuid' => isset($entity_email_to) ? $entity_email_to->uid : NULL,
@@ -82,6 +87,7 @@ function entity_email_rules_send_message
'mail_to' => isset($entity_email_mailto) ? $entity_email_mailto : NULL,
'mail_from' => isset($entity_email_mailfrom) ? $entity_email_mailfrom : NULL,
'mail_replyto' => isset($entity_email_replyto) ? $entity_email_replyto : NULL,
+ 'webform_data' => isset($webform_data) ? $webform_data : NULL,
);
$entity_email_save = isset($entity_email_save) ? TRUE : FALSE;
entity_email_send($entity_email_name, $params, $entity_email_save);
diff -uprb a/includes/entity_email.admin.inc b/includes/entity_email.admin.inc
--- includes/entity_email.admin.inc 2013-11-04 15:05:56.000000000 +0530
+++ includes/entity_email.admin.inc 2015-06-16 21:25:14.000000000 +0530
@@ -9,7 +9,9 @@
* Generate the Entity Email Type editing form.
*/
function entity_email_type_form($form, &$form_state, $entity_email_type, $op = 'edit') {
- $field_language = NULL;
+ //@radu enable language targeting
+ global $language;
+ $field_language = $language->language;
if ($op == 'clone') {
$entity_email_type->name .= '';
@@ -37,14 +39,6 @@ function entity_email_type_form($form, &
'#required' => TRUE,
'#disabled' => !(isset($entity_email_type->is_new) && $entity_email_type->is_new),
);
- $form['subject'] = array(
- '#type' => 'textfield',
- '#title' => t('Subject'),
- '#default_value' => $entity_email_type->subject,
- '#description' => t('The subject line of the email template. May include tokens of any token type specified below.'),
- '#maxlength' => 255,
- '#required' => TRUE,
- );
$form['mail'] = array(
'#prefix' => '<div id="mail-type-wrapper">',
'#suffix' => '</div>',
@@ -55,6 +49,33 @@ function entity_email_type_form($form, &
// Attach extra fields.
field_attach_form('entity_email_type', $entity_email_type, $form['mail'], $form_state, $field_language);
+ //patch by alin .. add template email field
+ $r = db_select('fieldable_panels_panes', 'fp')
+ ->fields('fp', array('fpid', 'admin_title', 'language'))
+ ->condition('fp.bundle', 'email_template')
+ ->orderBy('admin_title')
+ ->orderBy('language')
+ ->execute();
+ //check if there are multi languages active
+ $languages = language_list();
+ if(isset($languages['en'])) unset($languages['en']);
+ $isMultilanguage = count($languages) > 1;
+
+ $template_fpid_options = array();
+ foreach($r as $record) {
+ $template_fpid_options[$record->fpid] = $isMultilanguage ? $record->language.' - '.$record->admin_title : $record->admin_title;
+ }
+
+ $form['template_fpid'] = array(
+ '#type' => 'select',
+ '#title' => t('Email template'),
+ '#options' => $template_fpid_options,
+ '#required' => false,
+ '#default_value' => $entity_email_type->template_fpid,
+ '#empty_option' => t('- Select -'),
+ );
+
+
$form['send_email'] = array(
'#type' => 'checkbox',
'#title' => t('Send a test email.'),
@@ -104,6 +125,7 @@ function entity_email_type_form_submit(&
'cuid' => $user,
'fuid' => $user,
'mail_to' => $form_state['values']['test_email'],
+ 'template_fpid' => $form_state['values']['template_fpid']
);
$email = entity_email_send($form_state['values']['name'], $params);
}
@@ -124,7 +146,7 @@ function entity_email_type_token_help()
);
$tokens['token_tree'] = array(
'#theme' => 'token_tree',
- '#token_types' => array('site', 'current-user', 'entity-email-from', 'entity-email-to', 'entity-email-dynamic', 'entity-email-node',),
+ '#token_types' => array('site', 'current-user', 'entity-email-from', 'entity-email-to', 'entity-email-dynamic', 'entity-email-node', 'webform'),
'#global_types' => FALSE,
);
}
diff -uprb a/includes/entity_email.entity_email.inc b/includes/entity_email.entity_email.inc
--- includes/entity_email.entity_email.inc 2013-11-04 15:05:56.000000000 +0530
+++ includes/entity_email.entity_email.inc 2015-06-16 21:59:16.000000000 +0530
@@ -33,6 +33,8 @@ class EntityEmail extends Entity {
public $subject = '';
+ public $template_fpid;
+
public $mail_body = '';
public $mail_body_plain = '';
@@ -74,6 +76,10 @@ class EntityEmail extends Entity {
$this->mail_to = $account->mail;
}
+ if(!empty($this->mail_to)) {
+ $this->mail_to = trim($this->mail_to);
+ }
+
// Load email type.
$entity_email_type = $this->getType();
@@ -84,6 +90,7 @@ class EntityEmail extends Entity {
$this->subject = token_replace($entity_email_type->getSubject(), $substitutions);
$this->mail_body = token_replace($entity_email_type->getMailBody(), $substitutions);
$this->mail_body_plain = token_replace($entity_email_type->getMailBodyPlain(), $substitutions);
+ $this->template_fpid = $entity_email_type->getTemplateFPID();
}
else {
watchdog('entity_email', 'Could not retrieve the email template', $values, WATCHDOG_ERROR);
diff -uprb a/includes/entity_email.entity_email_type.inc b/includes/entity_email.entity_email_type.inc
--- includes/entity_email.entity_email_type.inc 2013-11-04 15:05:56.000000000 +0530
+++ includes/entity_email.entity_email_type.inc 2015-06-16 23:32:54.000000000 +0530
@@ -21,6 +21,7 @@ class EntityEmailTypeUIController extend
// Extract form values.
form_state_values_clean($form_state);
+
foreach ($form_state['values'] as $key => $value) {
if ($key != 'mail') {
$entity->$key = $value;
@@ -98,6 +99,8 @@ class EntityEmailType extends Entity {
public $subject;
+ public $template_fpid;
+
public function __construct($values = array()) {
parent::__construct($values, 'entity_email_type');
}
@@ -118,7 +121,49 @@ class EntityEmailType extends Entity {
* A string with the content from the field.
*/
public function getSubject($langcode = LANGUAGE_NONE, $options = array()) {
- return $this->subject;
+
+ // Set default values.
+ $options += array(
+ // As the text is already sanitized, it does not really matter if we
+ // enable sanitizing, as it would be default. However, one can change the
+ // field instance (e.g. to have no text processing) we make sure we still
+ // properly sanitize the value.
+ 'sanitize' => TRUE,
+ // The field name from which the text should be extracted.
+ 'field name' => ENTITY_EMAIL_FIELD_MAIL_SUBJECT,
+ // Determine if the text of just a single delta should be returned.
+ 'partials' => FALSE,
+ 'partial delta' => 0,
+ );
+
+ $field_name = ENTITY_EMAIL_FIELD_MAIL_SUBJECT;
+
+ if (!$field = field_info_field($field_name)) {
+ throw new Exception(format_string('Field %field does not exist.', array('%field' => $field_name)));
+ }
+
+ if (empty($field['settings']['entity_email_text'])) {
+ throw new Exception(format_string('Field %field is not a entity_email_mail_body.', array('%field' => $field_name)));
+ }
+
+ $wrapper = entity_metadata_wrapper('entity_email_type', $this);
+
+ //if (empty($langcode) && module_exists('locale')) {
+ // Get the langcode from the current language.
+ global $language;
+ $langcode = language_default()->language;
+ //}
+
+ // Let the metadata wrapper deal with the language.
+ $value_wrapper = $wrapper->language($langcode)->$options['field name'];
+
+ $property_item = $value_wrapper->value($options);
+
+ return $property_item;
+ }
+
+ public function getTemplateFPID() {
+ return $this->template_fpid;
}
/**
@@ -163,11 +208,11 @@ class EntityEmailType extends Entity {
$wrapper = entity_metadata_wrapper('entity_email_type', $this);
- if (empty($langcode) && module_exists('locale')) {
+ //if (empty($langcode) && module_exists('locale')) {
// Get the langcode from the current language.
global $language;
- $langcode = $language->language;
- }
+ $langcode = language_default()->language;
+ //}
// Let the metadata wrapper deal with the language.
$value_wrapper = $wrapper->language($langcode)->$options['field name'];
@@ -219,19 +264,57 @@ class EntityEmailType extends Entity {
$property = entity_metadata_wrapper('entity_email_type', $this);
- if (empty($langcode) && module_exists('locale')) {
+ //if (empty($langcode) && module_exists('locale')) {
// Get the langcode from the current language.
global $language;
- $langcode = $language->language;
- }
+ $langcode = language_default()->language;
+ //}
// Let the metadata wrapper deal with the language.
$property = $property->language($langcode)->$options['field name'];
$property_item = $property->value($options);
+
+ //patch by alin .. get template and include the value
+ if($this->template_fpid) {
+ global $theme;
+ if ($theme === variable_get('admin_theme', 'seven')) { // change the theme to the front end theme
+ $panelRender = $this->renderAdminAreaPanelEmailTpl($property_item['value']);
+ }
+ else {
+ $panel = fieldable_panels_panes_load($this->template_fpid);
+ $panel->mailBody = $property_item['value'];
+ $element = fieldable_panels_pane_view($panel, $this->name, $langcode);
+ $panelRender = render($element);
+ }
+
+
+ return $panelRender;
+ }
+
+ //
+
return $property_item['value'];
}
+ function renderAdminAreaPanelEmailTpl($mailBody) {
+ $variables = array();
+ $variables['elements'] = array('#fieldable_panels_pane' => new stdClass());
+ $variables['elements']['#fieldable_panels_pane']->mailBody = $mailBody;
+ // Extract the variables to a local namespace
+ extract($variables, EXTR_SKIP);
+
+ $tplFile = DRUPAL_ROOT.'/'.drupal_get_path('theme', variable_get('theme_default', 'bartik')).'/templates/email/fieldable-panels-pane--email-template.tpl.php';
+ if(!file_exists($tplFile)) {
+ $tplFile = DRUPAL_ROOT.'/'.drupal_get_path('theme', 'npro_master').'/templates/email/fieldable-panels-pane--email-template.tpl.php';
+ }
+
+ // Start output buffering
+ ob_start();
+ include $tplFile;
+ return ob_get_clean();
+ }
+
/**
* Retrieves the configured mail body in a certain language.
*
@@ -273,11 +356,11 @@ class EntityEmailType extends Entity {
$property = entity_metadata_wrapper('entity_email_type', $this);
- if (empty($langcode) && module_exists('locale')) {
+ //if (empty($langcode) && module_exists('locale')) {
// Get the langcode from the current language.
global $language;
- $langcode = $language->language;
- }
+ $langcode = language_default()->language;
+ //}
// Let the metadata wrapper deal with the language.
$property = $property->language($langcode)->$options['field name'];
Only in /Users/piyuesh23/htdocs/acquia/opera/sites/all/modules/user/entity_email/includes: translation.handler.entity_email_type.inc
Only in /Users/piyuesh23/htdocs/acquia/opera/sites/all/modules/user/entity_email/: theme_integration.patch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment