public static function Simplesitemap::get_sitemap_form_entity_data in Simple XML sitemap 8
Gets the entity_type_id and bundle_name of the form object if available and only if the sitemap supports this entity type through an existing plugin.
Parameters
object $form_state:
string $form_id:
Return value
array containing the entity_type_id and the bundle_name of the form object or FALSE if none found or not supported by an existing plugin.
1 call to Simplesitemap::get_sitemap_form_entity_data()
- simplesitemap_form_alter in ./
simplesitemap.module - Implements hook_form_alter.
File
- src/
Simplesitemap.php, line 39 - Contains \Drupal\simplesitemap\Simplesitemap.
Class
- Simplesitemap
- Simplesitemap class.
Namespace
Drupal\simplesitemapCode
public static function get_sitemap_form_entity_data($form_state, $form_id) {
// Get all simplesitemap plugins.
$manager = \Drupal::service('plugin.manager.simplesitemap');
$plugins = $manager
->getDefinitions();
// Go through simplesitemap plugins and check if one of them declares usage
// of this particular form. If that's the case, get entity type id of the
// plugin definition and assume the bundle to be of the same name as the
// entity type id.
foreach ($plugins as $plugin) {
if (isset($plugin['form_id']) && $plugin['form_id'] === $form_id) {
return array(
'entity_type_id' => $plugin['id'],
'bundle_name' => $plugin['id'],
);
}
}
// Else get entity type id and bundle name from the form if available and only
// if a simplesitemap plugin of the same entity type exists.
$form_entity = self::get_form_entity($form_state);
if ($form_entity !== FALSE) {
$form_entity_type_id = $form_entity
->getEntityTypeId();
if (isset($plugins[$form_entity_type_id])) {
if (!isset($plugins[$form_entity_type_id]['form_id']) || $plugins[$form_entity_type_id]['form_id'] === $form_id) {
return array(
'entity_type_id' => $form_entity_type_id,
'bundle_name' => $form_entity
->Id(),
);
}
}
}
// If both methods of getting simplesitemap entity data for this form
// failed, return FALSE.
return FALSE;
}