Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derivatives Example Missing #51

Open
bhanu951 opened this issue May 9, 2023 · 9 comments
Open

Derivatives Example Missing #51

bhanu951 opened this issue May 9, 2023 · 9 comments
Assignees

Comments

@bhanu951
Copy link
Contributor

bhanu951 commented May 9, 2023

Here is the reference example for Block Derivative Example

@bhanu951
Copy link
Contributor Author

derivative_examples.zip

@selwynpolit I have created example for Derivatives. It includes examples for Block and Menu Derivatives. It doesn't have much of description text but working example code. If you can have a look and give me feedback I can include Queue and Local Task derivatives as well.

@selwynpolit
Copy link
Owner

Thanks @bhanu951 What is your use case? I've never used these before and a quick google didn't return a very clear reason why we'd use these.

@selwynpolit
Copy link
Owner

@selwynpolit
Copy link
Owner

and from https://www.drupal.org/docs/drupal-apis/plugin-api/plugin-api-overview
Plugin Derivatives allow a single plugin to act in place of many. This is useful for situations where user entered data might have an impact on available plugins. For example, if menus are placed on screen using a plugin, then when the site administrator creates a new menu, that menu must be available for placement without needing a new plugin to do so. Plugin Derivatives also support the user interface by allowing it to display multiple plugins in place of one, allowing for help text specific to the use case to be rendered and utilized. The primary purpose of plugin derivatives is to provide partially configured plugins as "first class" plugins that are indistinguishable in the UI from other plugins, thus reducing the burden on administrators using these plugins.

@bhanu951
Copy link
Contributor Author

bhanu951 commented May 2, 2024

@selwynpolit Block derivatives in Drupal 8+ are used to multiple blocks with arguments.

Drupal 7 equivalent code is


hook_block_info() {
  $number_blocks = variable_get('my_module_number_of_blocks', 0);
  $x=0
  while ($x < $number_of_blocks) {
    $blocks['myblock-' . $x] = array(
      'info' => t('Block ' . $x), 
      'cache' => DRUPAL_NO_CACHE,
    );
  }
  return $blocks
}

@bhanu951
Copy link
Contributor Author

bhanu951 commented May 8, 2024

One of the popular module using it https://www.drupal.org/project/menu_block

@selwynpolit
Copy link
Owner

@bhanu951 How does this look?

https://selwynpolit.github.io/d9book/plugins#derivatives

Feel free to add or change it. I really appreciate your extensive examples. I am curious if you have actually used this for a project and if you could describe the use case.

@selwynpolit selwynpolit self-assigned this May 15, 2024
@bhanu951
Copy link
Contributor Author

bhanu951 commented May 21, 2024

@selwynpolit

How does this look?

It looks good but I think its good to have a separate section instead of it being sub-section in Plugins. As this topic is a rare one.

I am curious if you have actually used this for a project and if you could describe the use case.

Its been long time(6-7 Years) since I used block derivatives. I don't remember all the details but , the requirement was to have a form where some calendar events are created and after events are created we need to create a new block and assign it to a region.

Other use case was to display the latest published content from all the content types in separate blocks.

Here is one good example for Queue Derivatives.

And a good post in regards Derivatives

@bhanu951
Copy link
Contributor Author

Created PR #117 to include queue and local task derivatives.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants