Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
gsap
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
gsap
Merge requests
!2
Issue
#3340975
: Allow manually adding plugins
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Issue
#3340975
: Allow manually adding plugins
issue/gsap-3340975:3340975-allow-manually-adding
into
1.0.x
Overview
0
Commits
1
Pipelines
0
Changes
2
Merged
Bryan Sharpe
requested to merge
issue/gsap-3340975:3340975-allow-manually-adding
into
1.0.x
2 years ago
Overview
0
Commits
1
Pipelines
0
Changes
2
Expand
0
0
Merge request reports
Compare
1.0.x
version 1
25fbacb8
2 years ago
1.0.x (base)
and
latest version
latest version
25fbacb8
1 commit,
2 years ago
version 1
25fbacb8
1 commit,
2 years ago
2 files
+
128
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
src/Form/Admin.php
+
105
−
0
Options
@@ -76,18 +76,123 @@ class Admin extends ConfigFormBase {
],
];
// Keyword detection settings.
$key_values
=
$config
->
get
(
'custom_libs'
);
if
(
$form_state
->
get
(
'key_values'
)
===
NULL
)
{
$form_state
->
set
(
'key_values'
,
is_array
(
$key_values
)
?
$key_values
:
[]);
}
$form
[
'custom_libs'
]
=
[
'#type'
=>
'details'
,
'#title'
=>
$this
->
t
(
'Additional Libraries'
),
'#description'
=>
$this
->
t
(
"The name will be created as a library of 'gsap/[key]'. These will NOT be added to the page automatically."
),
'#open'
=>
TRUE
,
'#tree'
=>
TRUE
,
'#attributes'
=>
[
'id'
=>
'edit-custom'
],
];
foreach
(
$form_state
->
get
(
'key_values'
)
as
$delta
=>
$key_value
)
{
$form
[
'custom_libs'
][
$delta
]
=
[
'#type'
=>
'details'
,
'#title'
=>
$this
->
t
(
'Name: @key'
,
[
'@key'
=>
isset
(
$key_values
[
$delta
])
?
key
(
$key_values
[
$delta
])
:
$this
->
t
(
'**Not yet saved**'
),
]),
'#open'
=>
TRUE
,
];
$form
[
'custom_libs'
][
$delta
][
'key'
]
=
[
'#type'
=>
'textfield'
,
'#title'
=>
$this
->
t
(
'Library Key'
),
'#description'
=>
$this
->
t
(
"Will be added as gsap/[key]"
),
'#element_validate'
=>
[
'::validateLibKey'
],
'#default_value'
=>
isset
(
$key_values
[
$delta
])
?
key
(
$key_values
[
$delta
])
:
NULL
,
];
$form
[
'custom_libs'
][
$delta
][
'value'
]
=
[
'#type'
=>
'textfield'
,
'#title'
=>
$this
->
t
(
'Path to library'
),
'#description'
=>
$this
->
t
(
'Either URL or absolute path from docroot.'
),
'#default_value'
=>
isset
(
$key_values
[
$delta
])
?
reset
(
$key_values
[
$delta
])
:
NULL
,
];
$form
[
'custom_libs'
][
$delta
][
'remove'
]
=
[
'#type'
=>
'submit'
,
'#value'
=>
$this
->
t
(
'Remove'
),
'#name'
=>
"remove_
$delta
"
,
'#submit'
=>
[[
$this
,
'removeLib'
]],
'#ajax'
=>
[
'callback'
=>
[
$this
,
'ajaxLibs'
],
'wrapper'
=>
'edit-custom'
,
],
'#attributes'
=>
[
'class'
=>
[
'field-add-more-submit'
]],
];
}
$form
[
'custom_libs'
][
'add'
]
=
[
'#type'
=>
'submit'
,
'#value'
=>
$this
->
t
(
'Add new library'
),
'#submit'
=>
[[
$this
,
'addLib'
]],
'#ajax'
=>
[
'callback'
=>
[
$this
,
'ajaxLibs'
],
'wrapper'
=>
'edit-custom'
,
],
'#attributes'
=>
[
'class'
=>
[
'field-add-more-submit'
]],
];
return
$form
;
}
/**
* Validates lib keys.
*/
public
static
function
validateLibKey
(
$element
,
&
$form_state
)
{
$value
=
$element
[
'#value'
];
if
(
!
preg_match
(
'/^[a-z_]+$/'
,
$value
))
{
$form_state
->
setError
(
$element
,
t
(
'Please enter lower case letters only and no spaces.'
));
}
}
/**
* Submit for libs.
*/
public
function
ajaxLibs
(
array
&
$form
,
FormStateInterface
$form_state
)
{
return
$form
[
'custom_libs'
];
}
/**
* Remove lib callback.
*/
public
function
removeLib
(
array
&
$form
,
FormStateInterface
$form_state
)
{
$form_state
->
setRebuild
(
TRUE
);
$delta
=
$form_state
->
getTriggeringElement
()[
'#array_parents'
][
1
];
$key_values
=
$form_state
->
get
(
'key_values'
);
unset
(
$key_values
[
$delta
]);
$form_state
->
set
(
'key_values'
,
$key_values
);
}
/**
* Add lib callback.
*/
public
function
addLib
(
array
&
$form
,
FormStateInterface
$form_state
)
{
$form_state
->
setRebuild
(
TRUE
);
$key_values
=
$form_state
->
get
(
'key_values'
);
$key_values
[]
=
[];
$form_state
->
set
(
'key_values'
,
$key_values
);
}
/**
* {@inheritdoc}
*/
public
function
submitForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{
$libraries
=
array_values
(
array_filter
(
$form_state
->
getValue
(
'libs'
)));
$custom
=
$form_state
->
cleanValues
()
->
getValue
(
'custom_libs'
);
$custom_libs
=
[];
foreach
(
$custom
as
$lib
)
{
if
(
!
empty
(
$lib
[
'key'
])
&&
!
empty
(
$lib
[
'value'
]))
{
$custom_libs
[]
=
[
$lib
[
'key'
]
=>
$lib
[
'value'
]];
}
}
$this
->
configFactory
->
getEditable
(
'gsap.settings'
)
->
set
(
'libs'
,
$libraries
)
->
set
(
'include_gsap'
,
$form_state
->
getValue
(
'include_gsap'
))
->
set
(
'include_libs'
,
$form_state
->
getValue
(
'include_libs'
))
->
set
(
'custom_libs'
,
$custom_libs
)
->
save
();
parent
::
submitForm
(
$form
,
$form_state
);
Loading