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

Allow Angular modules to provide dynamic HTML snippets #16078

Merged
merged 2 commits into from
Dec 13, 2019

Conversation

colemanw
Copy link
Member

@colemanw colemanw commented Dec 11, 2019

Overview

Supports afforms dynamic templates by allowing angular partials to be passed as strings not just file paths.

See https://lab.civicrm.org/extensions/afform/merge_requests/16

Before

An Angular module must put HTML partials into specific files that live adjacent to the extension (e.g. files/civicrm/ext/myextension/ang/foo.html).

After

An Angular module may generate HTML partials dynamically - using a callback function, e.g.

function mymod_civicrm_angularModules(&$modules) {
  $modules['mymod'] = [
    // ...
    'partialsCallback' => 'mymod_get_partials',
  ];
}

function mymod_get_partials(string $moduleName, array $module) {
  return [
    '~/mymod/greeting.html' => '<p>Hello world!</p>',
  ];
}

Comments

I thought about a lot of clever ways to do this, settled on a one-liner. KISS.

@civibot
Copy link

civibot bot commented Dec 11, 2019

(Standard links)

@civibot civibot bot added the master label Dec 11, 2019
@colemanw
Copy link
Member Author

@civicrm-builder retest this please

This is similar to the antecedent commit which used a field 'snippets' that
contained a list of HTML files and their content. However, this
uses a callback function instead of providing the full HTML content.

This makes it safer to work with the Angular metadata without needing to
load the content of all partials into memory.
@totten
Copy link
Member

totten commented Dec 12, 2019

Yeah, I'd also spent a lot of time looking for a "elegant" way (in particular, making the different forms of local-files and dynamic-files use similar notations). It's tough row, so +1 on the KISS approach.

However, I've pushed an update to use a slightly different contract. As discussed in afform!16, the snippets => [string $filename => string $html] contract means that it would load the full HTML content of all *.aff.html files even in the case where they're not needed. (Which is more likely to be common since Afform is biased toward standalone base-pages.) The update uses a callback instead of an array of HTML content. I'll update the description with more details.

@totten totten added the merge ready PR will be merged after a few days if there are no objections label Dec 12, 2019
@totten
Copy link
Member

totten commented Dec 12, 2019

The r-run seems good on top of afform!16. However, since I changed it a bit from the original submission, I'm marked "merge ready" in case there's more feedback.

@totten totten changed the title Allow angular modules to provide dynamic html snippets Allow Angular modules to provide dynamic HTML snippets Dec 13, 2019
@colemanw
Copy link
Member Author

Well now that "HTML" has been properly capitalized in the title, it's definitely ready to merge ;)

@colemanw colemanw added merge on pass and removed merge ready PR will be merged after a few days if there are no objections labels Dec 13, 2019
@colemanw colemanw merged commit a655f14 into civicrm:master Dec 13, 2019
@colemanw colemanw deleted the snippets branch December 13, 2019 02:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants