Problem/Motivation
componentMetadata.path gives the path relative to the Drupal root. If the Drupal site is not at the root of the host, this is not enough to get full path to the component. It would be missing the base_path().
Example use case: A SDC which provides markup that refers to an image that is included in the SDC. The src attribute would need to include the full path to the image file.
Proposed resolution
Create componentMetadata.fullPath which is like base_path() . componentMetadata.path. Alternatively, create componentMetadata.base_path
Remaining tasks
Decide which to do. Implement.
User interface changes
None.
Introduced terminology
None.
API changes
Addition of componentMetadata.fullPath.
Data model changes
None.
Release notes snippet
Issue fork drupal-3567767
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
liam morlandComment #5
smustgrave commentedComment #6
pdureau commentedThanks Liam for your contribution.
Because you sue
base_path(), I guess the distinction is not betweenpathandfullPathbut about server and web path.Looking at Core and some contrib themes, it seems
componentMetadata.pathis rarely used:The usage is split between:
{{ include (componentMetadata.path ~ '/images/arrow.svg') }},{{ source(componentMetadata.path ~ '/icons/' ~ icon|default('knife') ~ '.svg') }}...<img src="{{ componentMetadata.path ~ '/' ~ media.src }}">...If I understand well,
componentMetadata.pathis the good solution for server side path, but works on Web side (href,src...) only ifbase_path() === "/". That's it?Comment #7
liam morlandYes, there currently isn't a way to get the
base_path()inside an SDC.Comment #8
smustgrave commentedMaybe a test case showing why this is needed will help, regardless will need test coverage
Comment #9
liam morlandI have added an example use case to the issue summary. Tests are still needed.
Comment #10
oily commentedRe: #9 Does this require a CR? The example could be added there, too?
Comment #11
oily commentedWould core/tests/Drupal/FunctionalTests/Theme/OliveroTest.php be a place to put the test?