public static function ViewsAddButtonDefault::generateUrl in Views Add Button 8
Same name and namespace in other branches
- 2.0.x src/Plugin/views_add_button/ViewsAddButtonDefault.php \Drupal\views_add_button\Plugin\views_add_button\ViewsAddButtonDefault::generateUrl()
Generate the add button URL.
Parameters
string $entity_type: Entity type ID.
string $bundle: Bundle ID.
array $options: Array of options to be passed to the Url object.
string $context: Module-specific context string.
Return value
\Drupal\Core\Url Url object which is used to construct the add button link.
File
- src/
Plugin/ views_add_button/ ViewsAddButtonDefault.php, line 46
Class
- ViewsAddButtonDefault
- Default plugin for Views Add Button.
Namespace
Drupal\views_add_button\Plugin\views_add_buttonCode
public static function generateUrl($entity_type, $bundle, array $options, $context = '') {
/*
* Since the create route is difficult to determine
* from entity annotations (there is not a standard
* name for a create/register form), We will make
* an assumption that a no-bundle entity has the format
* {entity_type}/add , and bundled entities are of the
* type {entity_type}/add/{bundle} . Differences are
* handled in other ViewsAddButton plugins.
*/
$u = $entity_type === $bundle ? '/' . $entity_type . '/add' : '/' . $entity_type . '/add/' . $bundle;
// Create URL from the data above.
$url = Url::fromUserInput($u, $options);
return $url;
}