Zum Inhalt springen

Powermail 2.0.x: Felder mit weiterer Eigenschaft ausstatten

Erstellt am 10. September 2014 · 3 Antworten · letzte Antwort am 27. Oktober 2014

Tags: Extbase, Powermail, Tipp

einpraegsam.​net ·

Weil ich gerade darüber gestolpert bin, hier eine kurze Anleitung, wie man ein neues Feld für powermail 2.0 für die Tabelle tx_powermail_domain_model_fields einfügen kann. Hier zeige ich, wie man einen Placeholder mit einbauen kann (btw. Placeholder sind standardmäßig ab powermail 2.1 mit an Board).

Erforderlich ist eine weitere Extension - hier in Kurzform.

EXT:ext/ext_typoscript_setup.txt

config.tx_extbase{
	persistence{
		classes{
			Tx_Powermail_Domain_Model_Forms {
				subclasses {
					0 = Tx_Ext_Domain_Model_Powermailform
				}
			}
			Tx_Powermail_Domain_Model_Pages {
				subclasses {
					0 = Tx_Ext_Domain_Model_Powermailpage
				}
			}
			Tx_Powermail_Domain_Model_Fields {
				subclasses {
					0 = Tx_Ext_Domain_Model_Powermailfield
				}
			}
			Tx_Ext_Domain_Model_Powermailform {
				mapping {
					tableName = tx_powermail_domain_model_forms
				}
			}
			Tx_Ext_Domain_Model_Powermailpage {
				mapping {
					tableName = tx_powermail_domain_model_pages
				}
			}
			Tx_Ext_Domain_Model_Powermailfield {
				mapping {
					tableName = tx_powermail_domain_model_fields
				}
			}
		}
	}
	objects {
		Tx_Powermail_Domain_Repository_FormsRepository.className = Tx_Ext_Domain_Repository_PowermailformRepository
	}
}

EXT:ext/ext_tables.sql

#
# Table structure for table 'tx_powermail_domain_model_fields'
#
CREATE TABLE tx_powermail_domain_model_fields (
	tx_ext_powermail_placeholder varchar(255) DEFAULT '' NOT NULL
);

EXT:ext/ext_tables.php

t3lib_extMgm::addStaticFile($_EXTKEY, 'Configuration/TypoScript/', 'Main Template');

/**
 * EXTEND TABLE: powermail (new placeholder-field - can eventually be replaced with new powermail functionality on powermail 2.1)
 */
t3lib_div::loadTCA('tx_powermail_domain_model_fields');
$tempColumns = array (
	# show new placeholder field
	'tx_ext_powermail_placeholder' => array (
		'exclude' => 1,
		'label' => 'LLL:EXT:ext/locallang_db.xml:powermail.tx_ext_powermail_placeholder',
		'config' => array (
			'type' => 'input',
			'size' => 30,
			'eval' => 'trim'
		)
	),
);

t3lib_extMgm::addTCAcolumns('tx_powermail_domain_model_fields',$tempColumns,1);
t3lib_extMgm::addToAllTCAtypes('tx_powermail_domain_model_fields','tx_ext_powermail_placeholder', '', 'after:title');

EXT:ext/Configuration/TypoScript/setup.txt

plugin.tx_powermail {
	view {
		templateRootPath = EXT:ext/Resources/Private/Templates/
		partialRootPath = EXT:ext/Resources/Private/Partials/
		layoutRootPath = EXT:ext/Resources/Private/Layouts/
	}
}

EXT:ext/Classes/Domain/Model/Powermailfield.php

<?php

/**
 * Class Tx_Ext_Domain_Model_Powermailfield
 *
 * Extends the fields model of powermail
 */
class Tx_Ext_Domain_Model_Powermailfield extends Tx_Powermail_Domain_Model_Fields {

	/**
	 * attribute for placeholder field
	 *
	 * @var string $txExtPowermailPlaceholder
	 */
	protected $txExtPowermailPlaceholder;


	/**
	 * Returns the placeholder
	 *
	 * @return string $txExtPowermailPlaceholder
	 */
	public function getTxExtPowermailPlaceholder() {
		return $this->txExtPowermailPlaceholder;
	}

	/**
	 * Sets the placeholder
	 *
	 * @param string $txExtPowermailPlaceholder
	 * @return void
	 */
	public function SetTxExtPowermailPlaceholder($txExtPowermailPlaceholder) {
		$this->txExtPowermailPlaceholder = $txExtPowermailPlaceholder;
	}
}

EXT:ext/Classes/Domain/Model/Powermailform.php

<?php

/**
 *
 *
 * @package powermail
 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
 *
 */
class Tx_Ext_Domain_Model_Powermailform extends Tx_Powermail_Domain_Model_Forms {

	/**
	 * pages
	 *
	 * @var Tx_Extbase_Persistence_ObjectStorage<Tx_Ext_Domain_Model_Powermailpage>
	 */
	protected $pages = NULL;

	/**
	 * @param Tx_Extbase_Persistence_ObjectStorage $pages
	 */
	public function setPages($pages) {
		$this->pages = $pages;
	}

	/**
	 * @return Tx_Extbase_Persistence_ObjectStorage
	 */
	public function getPages() {
		return $this->pages;
	}
}

EXT:ext/Classes/Domain/Model/Powermailpage.php

<?php

/**
 *
 *
 * @package powermail
 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
 *
 */
class Tx_Ext_Domain_Model_Powermailpage extends Tx_Powermail_Domain_Model_Pages {

	/**
	 * Powermail Fields
	 *
	 * @var Tx_Extbase_Persistence_ObjectStorage<Tx_Ext_Domain_Model_Powermailfield>
	 */
	protected $fields = NULL;

	/**
	 * @param Tx_Extbase_Persistence_ObjectStorage $fields
	 */
	public function setFields($fields) {
		$this->fields = $fields;
	}

	/**
	 * @return Tx_Extbase_Persistence_ObjectStorage
	 */
	public function getFields() {
		return $this->fields;
	}
}

EXT:ext/Classes/Domain/Model/Repository/PowermailformRepository.php

<?php


/**
 * FormsRepository
 *
 * @package powermail
 * @license http://www.gnu.org/licenses/lgpl.html
 * 			GNU Lesser General Public License, version 3 or later
 */
class Tx_Ext_Domain_Repository_PowermailformRepository extends Tx_Powermail_Domain_Repository_FormsRepository {}

Alle Templates, Partials und Layouts von Powermail müssten in die Extension kopiert werden (siehe Pfad im TypoScript oben).
Hier ein Beispiel für den Partial Input.html mit Placeholder:

{namespace vh=Tx_Powermail_ViewHelpers}

<div id="powermail_fieldwrap_{field.uid}" class="powermail_fieldwrap powermail_fieldwrap_text powermail_fieldwrap_{field.uid} {field.css} {field.marker} group">
	<label for="powermail_field_{field.marker}" class="powermail_label">
		{field.title}<f:if condition="{field.mandatory}"><span class="mandatory">*</span></f:if>
	</label>
	<f:if condition="{field.mandatory}">
		<f:then>
			<f:form.textfield id="powermail_field_{field.marker}" name="field[{field.uid}]" value="{vh:Misc.PrefillField(field: '{field}')}" class="powermail_field powermail_input {vh:Misc.ValidationClass(field: '{field}')} {vh:Misc.ErrorClass(field: '{field}', class: 'powermail_field_error')}" placeholder="{field.txExtPowermailPlaceholder}" required="{field.mandatory}" />
		</f:then>
		<f:else>
			<f:form.textfield id="powermail_field_{field.marker}" name="field[{field.uid}]" value="{vh:Misc.PrefillField(field: '{field}')}" class="powermail_field powermail_input {vh:Misc.ValidationClass(field: '{field}')} {vh:Misc.ErrorClass(field: '{field}', class: 'powermail_field_error')}" placeholder="{field.txExtPowermailPlaceholder}" />
		</f:else>
	</f:if>
</div>

Die Locallang Datei muss natürlich auch noch angelegt werden (siehe ext_tables.php).
In dem Beispiel wollen wir mit dieser Extension die Template-Pfade von Powermail mit eigenen Pfaden überschreiben. Das funktioniert natürlich nur, wenn das Static Template von "ext" nach dem Static Template von "powermail" kommt!

Ich hoffe ich habe in der Eile nichts übersehen beim Abtippen.

Cheers, Alex

haraldg ·

Hi!
Stehe mit der Lösung gerade etwas an, daher beim alten Beitrag angehängt: wenn ich so wie oben bzw. in der Doku beschrieben eine Eigenschaft hinzufüge, ist es beim Rendern des Formulars wie gewünscht verfügbar.
Das Aber: in den partials, wo {powermail_all} zusammengebaut wird, steht die neue Eigenschaft nicht bereit. Die Debug-Ausgabe von {answer.field} zeigt auch, dass nicht die eigene Klasse verwendet wird, sondern das Original. Ich vermute mal, dass da nochmal einige andere Klassen überschrieben werden müssen, damit es auch über den Weg Mail -> Answers -> Field klappt, habe es aber leider nicht hinbekommen.
Alles recht viel Aufwand für eine - auf den ersten Blick - Kleinigkeit... :-(

Habt ihr da einen Tipp dazu?

Danke, Harald

einpraegsam.​net ·

Hallo,

korrekt, das ist relativ viel Aufwand. Hier hat extbase definitiv ein Nachteil im Vergleich zur alten piBase Programmierung - dort hat ein "select * from ..." schon viel gerissen.

Das hat aber nichts mit {powermail_all} zu tun. Dort steht standardmäßig nur label und value zur Verfügung.