Skip to content

Commit

Permalink
Align method parameters for consistency/completeness.
Browse files Browse the repository at this point in the history
  • Loading branch information
demiankatz committed Jan 30, 2025
1 parent 17aa0c3 commit 1d11278
Showing 1 changed file with 55 additions and 23 deletions.
78 changes: 55 additions & 23 deletions module/VuFindTheme/src/VuFindTheme/View/Helper/AssetPipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,41 @@
*/
class AssetPipeline extends \Laminas\View\Helper\AbstractHelper
{
/**
* Array of accumulated scripts.
*
* @return
*/
/**
* Add raw CSS to the pipeline.
*
* @param string $css Raw CSS.
* @param string $css Raw CSS.
* @param array $attributes Extra attributes for style tag
*
* @return void
*/
public function appendStyle(string $css): void
public function appendStyle(string $css, array $attributes = []): void
{
$this->getView()->plugin('headStyle')->appendStyle($css);
$this->getView()->plugin('headStyle')->appendStyle($css, $attributes);
}

/**
* Add an entry to the list of stylesheets.
*
* @param string $href Stylesheet href
* @param string $href Stylesheet href
* @param string $media Media
* @param string $conditionalStylesheet Any conditions
* @param array $extras Array of extra attributes
*
* @return void
*/
public function appendStylesheet(string $href): void
{
$this->getView()->plugin('headLink')->appendStylesheet($href);
public function appendStylesheet(
string $href,
string $media = 'screen',
string $conditionalStylesheet = '',
array $extras = []
): void {
$this->getView()->plugin('headLink')->appendStylesheet($href, $media, $conditionalStylesheet, $extras);
}

/**
Expand All @@ -86,13 +99,20 @@ public function forcePrependStylesheet(
/**
* Clear the list of stylesheets, re-establishing it with the provided one.
*
* @param string $href Stylesheet href
* @param string $href Stylesheet href
* @param string $media Media
* @param string $conditionalStylesheet Any conditions
* @param array $extras Array of extra attributes
*
* @return void
*/
public function setStylesheet(string $href): void
{
$this->getView()->plugin('headLink')->setStylesheet($href);
public function setStylesheet(
string $href,
string $media = 'screen',
string $conditionalStylesheet = '',
array $extras = []
): void {
$this->getView()->plugin('headLink')->setStylesheet($href, $media, $conditionalStylesheet, $extras);
}

/**
Expand All @@ -102,34 +122,43 @@ public function setStylesheet(string $href): void
* @param string $type Script type
* @param array $attrs Additional attributes for the script tag
* @param bool $allowArbitraryAttrs Should we allow arbitrary attributes in $attrs?
* @param string $position Position to output script (header or footer)
*
* @return void
*/
public function appendScript(
string $script,
string $type = 'text/javascript',
array $attrs = [],
bool $allowArbitraryAttrs = false
bool $allowArbitraryAttrs = false,
string $position = 'header'
) {
$headScript = $this->getView()->plugin('headScript');
$helperName = $position === 'header' ? 'headScript' : 'footScript';
$scriptHelper = $this->getView()->plugin($helperName);
if ($allowArbitraryAttrs) {
$headScript->setAllowArbitraryAttributes(true);
$scriptHelper->setAllowArbitraryAttributes(true);
}
$headScript->appendScript($script, $type, $attrs);
$scriptHelper->appendScript($script, $type, $attrs);
}

/**
* Add an entry to the list of script files.
*
* @param string $href Script href
* @param string $src Script src
* @param string $type Script type
* @param array $attrs Array of script attributes
* @param string $position Position to output script (header or footer)
*
* @return void
*/
public function appendScriptFile(string $href, string $position = 'header'): void
{
public function appendScriptFile(
string $src,
string $type = 'text/javascript',
array $attrs = [],
string $position = 'header'
): void {
$helper = $position === 'header' ? 'headScript' : 'footScript';
$this->getView()->plugin($helper)->appendFile($href);
$this->getView()->plugin($helper)->appendFile($src, $type, $attrs);
}

/**
Expand Down Expand Up @@ -159,20 +188,23 @@ public function forcePrependScriptFile(
* @param string $type Script type
* @param array $attrs Additional attributes for the script tag
* @param bool $allowArbitraryAttrs Should we allow arbitrary attributes in $attrs?
* @param string $position Position to output script (header or footer)
*
* @return void
*/
public function prependScript(
string $script,
string $type = 'text/javascript',
array $attrs = [],
bool $allowArbitraryAttrs = false
bool $allowArbitraryAttrs = false,
string $position = 'header'
) {
$headScript = $this->getView()->plugin('headScript');
$helperName = $position === 'header' ? 'headScript' : 'footScript';
$scriptHelper = $this->getView()->plugin($helperName);
if ($allowArbitraryAttrs) {
$headScript->setAllowArbitraryAttributes(true);
$scriptHelper->setAllowArbitraryAttributes(true);
}
$headScript->prependScript($script, $type, $attrs);
$scriptHelper->prependScript($script, $type, $attrs);
}

/**
Expand Down

0 comments on commit 1d11278

Please sign in to comment.