Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By ParisLiakos on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Issue links:
Description:
In Drupal 7 if an aggregator parser, fetcher or processor needed to provide a form in the aggregator settings page for its own settings, it had to implement hook_form_alter()
In Drupal 8 after converting those to plugins, any plugin that implements PluginFormInterface or even better extends AggregatorPluginSettingsBase can provide its settings directly in the plugin class, by implementing the required PluginFormInterface methods
The DefaultProcessor is a great example on how this can be accomplished
D7
/**
* Implements hook_form_aggregator_admin_form_alter().
*/
function MYMODULE_form_aggregator_admin_form_alter(&$form, $form_state) {
// Add my stuff in form array and then add my additional submit and validate handlers/callbacks
// in $form['#submit'] and $form['#validate'] arrays
}
D8
class myParser extends AggregatorPluginSettingsBase implements ParserInterface {
/**
* {@inheritdoc}
*/
public function parse(FeedInterface $feed) {
// Parse stuff
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, array &$form_state) {
// Just build my form here.
// Typically i should key it with my plugin type and then id to avoid conflicts.
$info = $this->getPluginDefinition();
$form['parser'][$info['id']]['my_awesome_setting'] = array(
'#type' => 'textfield',
'#title' => 'Fill me',
);
// Don't forget to actually return the $form array.
return $form;
}
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, array &$form_state) {
// If i need to apply some validation logic i can do so here.
// If not, and my plugin extends AggregatorPluginSettingsBase i dont even have to implement this method.
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, array &$form_state) {
// Save my stuff
}
}
Impacts:
Module developers