repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
themosis/framework
src/Forms/Fields/Types/CollectionType.php
CollectionType.metaboxSave
public function metaboxSave($value, int $post_id) { $this->setValue($value); $previous = get_post_meta($post_id, $this->getName(), false); if (is_null($value) || empty($value)) { delete_post_meta($post_id, $this->getName()); } elseif (empty($previous) && is_array($value)) { array_walk($value, function ($val) use ($post_id) { add_post_meta($post_id, $this->getName(), $val, false); }); } else { delete_post_meta($post_id, $this->getName()); array_walk($value, function ($val) use ($post_id, $previous) { add_post_meta($post_id, $this->getName(), $val, false); }); } }
php
public function metaboxSave($value, int $post_id) { $this->setValue($value); $previous = get_post_meta($post_id, $this->getName(), false); if (is_null($value) || empty($value)) { delete_post_meta($post_id, $this->getName()); } elseif (empty($previous) && is_array($value)) { array_walk($value, function ($val) use ($post_id) { add_post_meta($post_id, $this->getName(), $val, false); }); } else { delete_post_meta($post_id, $this->getName()); array_walk($value, function ($val) use ($post_id, $previous) { add_post_meta($post_id, $this->getName(), $val, false); }); } }
[ "public", "function", "metaboxSave", "(", "$", "value", ",", "int", "$", "post_id", ")", "{", "$", "this", "->", "setValue", "(", "$", "value", ")", ";", "$", "previous", "=", "get_post_meta", "(", "$", "post_id", ",", "$", "this", "->", "getName", "(", ")", ",", "false", ")", ";", "if", "(", "is_null", "(", "$", "value", ")", "||", "empty", "(", "$", "value", ")", ")", "{", "delete_post_meta", "(", "$", "post_id", ",", "$", "this", "->", "getName", "(", ")", ")", ";", "}", "elseif", "(", "empty", "(", "$", "previous", ")", "&&", "is_array", "(", "$", "value", ")", ")", "{", "array_walk", "(", "$", "value", ",", "function", "(", "$", "val", ")", "use", "(", "$", "post_id", ")", "{", "add_post_meta", "(", "$", "post_id", ",", "$", "this", "->", "getName", "(", ")", ",", "$", "val", ",", "false", ")", ";", "}", ")", ";", "}", "else", "{", "delete_post_meta", "(", "$", "post_id", ",", "$", "this", "->", "getName", "(", ")", ")", ";", "array_walk", "(", "$", "value", ",", "function", "(", "$", "val", ")", "use", "(", "$", "post_id", ",", "$", "previous", ")", "{", "add_post_meta", "(", "$", "post_id", ",", "$", "this", "->", "getName", "(", ")", ",", "$", "val", ",", "false", ")", ";", "}", ")", ";", "}", "}" ]
Handle collection field post meta registration. @param array $value @param int $post_id
[ "Handle", "collection", "field", "post", "meta", "registration", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/Fields/Types/CollectionType.php#L128-L147
train
themosis/framework
src/Forms/Transformers/IntegerToLocalizedStringTransformer.php
IntegerToLocalizedStringTransformer.reverseTransform
public function reverseTransform($data) { $value = parent::reverseTransform($data); return ! is_null($value) ? (int) $value : null; }
php
public function reverseTransform($data) { $value = parent::reverseTransform($data); return ! is_null($value) ? (int) $value : null; }
[ "public", "function", "reverseTransform", "(", "$", "data", ")", "{", "$", "value", "=", "parent", "::", "reverseTransform", "(", "$", "data", ")", ";", "return", "!", "is_null", "(", "$", "value", ")", "?", "(", "int", ")", "$", "value", ":", "null", ";", "}" ]
Convert a localized string to an integer value. @param string $data @throws Exceptions\DataTransformerException @return int
[ "Convert", "a", "localized", "string", "to", "an", "integer", "value", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/Transformers/IntegerToLocalizedStringTransformer.php#L16-L21
train
themosis/framework
src/Forms/Transformers/ChoiceToValueTransformer.php
ChoiceToValueTransformer.parseNumeric
protected function parseNumeric($value) { if (is_numeric($value)) { if (false !== strrpos($value, '.')) { return (float) $value; } return (int) $value; } return $value; }
php
protected function parseNumeric($value) { if (is_numeric($value)) { if (false !== strrpos($value, '.')) { return (float) $value; } return (int) $value; } return $value; }
[ "protected", "function", "parseNumeric", "(", "$", "value", ")", "{", "if", "(", "is_numeric", "(", "$", "value", ")", ")", "{", "if", "(", "false", "!==", "strrpos", "(", "$", "value", ",", "'.'", ")", ")", "{", "return", "(", "float", ")", "$", "value", ";", "}", "return", "(", "int", ")", "$", "value", ";", "}", "return", "$", "value", ";", "}" ]
Parse if a value is numeric and cast it to its correct type. @param string $value @return float|int
[ "Parse", "if", "a", "value", "is", "numeric", "and", "cast", "it", "to", "its", "correct", "type", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/Transformers/ChoiceToValueTransformer.php#L33-L44
train
themosis/framework
src/Core/ProviderRepository.php
ProviderRepository.loadManifest
public function loadManifest() { if ($this->files->exists($this->manifestPath)) { $manifest = $this->files->getRequire($this->manifestPath); if ($manifest) { return array_merge(['when' => []], $manifest); } } }
php
public function loadManifest() { if ($this->files->exists($this->manifestPath)) { $manifest = $this->files->getRequire($this->manifestPath); if ($manifest) { return array_merge(['when' => []], $manifest); } } }
[ "public", "function", "loadManifest", "(", ")", "{", "if", "(", "$", "this", "->", "files", "->", "exists", "(", "$", "this", "->", "manifestPath", ")", ")", "{", "$", "manifest", "=", "$", "this", "->", "files", "->", "getRequire", "(", "$", "this", "->", "manifestPath", ")", ";", "if", "(", "$", "manifest", ")", "{", "return", "array_merge", "(", "[", "'when'", "=>", "[", "]", "]", ",", "$", "manifest", ")", ";", "}", "}", "}" ]
Load the service provider manifest file. @throws \Illuminate\Contracts\Filesystem\FileNotFoundException @return array|null
[ "Load", "the", "service", "provider", "manifest", "file", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/ProviderRepository.php#L82-L91
train
themosis/framework
src/Core/ProviderRepository.php
ProviderRepository.compileManifest
public function compileManifest(array $providers) { /* * The service manifest should contain a list of all of the providers for * the application so we can compare it on each request to the service * and determine if the manifest should be recompiled or is current. */ $manifest = $this->freshManifest($providers); foreach ($providers as $provider) { $instance = $this->createProvider($provider); /* * When recompiling the service manifest, we will spin through each of the * providers and check if it's a deferred provider or not. If so we'll * add it's provided services to the manifest and note the provider. */ if ($instance->isDeferred()) { foreach ($instance->provides() as $service) { $manifest['deferred'][$service] = $provider; } $manifest['when'][$provider] = $instance->when(); } else { /* * If the service providers are not deferred, we will simply add it to an * array of eagerly loaded providers that will get registered on every * request to this application instead of "lazy" loading every time. */ $manifest['eager'][] = $provider; } } return $this->writeManifest($manifest); }
php
public function compileManifest(array $providers) { /* * The service manifest should contain a list of all of the providers for * the application so we can compare it on each request to the service * and determine if the manifest should be recompiled or is current. */ $manifest = $this->freshManifest($providers); foreach ($providers as $provider) { $instance = $this->createProvider($provider); /* * When recompiling the service manifest, we will spin through each of the * providers and check if it's a deferred provider or not. If so we'll * add it's provided services to the manifest and note the provider. */ if ($instance->isDeferred()) { foreach ($instance->provides() as $service) { $manifest['deferred'][$service] = $provider; } $manifest['when'][$provider] = $instance->when(); } else { /* * If the service providers are not deferred, we will simply add it to an * array of eagerly loaded providers that will get registered on every * request to this application instead of "lazy" loading every time. */ $manifest['eager'][] = $provider; } } return $this->writeManifest($manifest); }
[ "public", "function", "compileManifest", "(", "array", "$", "providers", ")", "{", "/*\n * The service manifest should contain a list of all of the providers for\n * the application so we can compare it on each request to the service\n * and determine if the manifest should be recompiled or is current.\n */", "$", "manifest", "=", "$", "this", "->", "freshManifest", "(", "$", "providers", ")", ";", "foreach", "(", "$", "providers", "as", "$", "provider", ")", "{", "$", "instance", "=", "$", "this", "->", "createProvider", "(", "$", "provider", ")", ";", "/*\n * When recompiling the service manifest, we will spin through each of the\n * providers and check if it's a deferred provider or not. If so we'll\n * add it's provided services to the manifest and note the provider.\n */", "if", "(", "$", "instance", "->", "isDeferred", "(", ")", ")", "{", "foreach", "(", "$", "instance", "->", "provides", "(", ")", "as", "$", "service", ")", "{", "$", "manifest", "[", "'deferred'", "]", "[", "$", "service", "]", "=", "$", "provider", ";", "}", "$", "manifest", "[", "'when'", "]", "[", "$", "provider", "]", "=", "$", "instance", "->", "when", "(", ")", ";", "}", "else", "{", "/*\n * If the service providers are not deferred, we will simply add it to an\n * array of eagerly loaded providers that will get registered on every\n * request to this application instead of \"lazy\" loading every time.\n */", "$", "manifest", "[", "'eager'", "]", "[", "]", "=", "$", "provider", ";", "}", "}", "return", "$", "this", "->", "writeManifest", "(", "$", "manifest", ")", ";", "}" ]
Compile the application service manifest file. @param array $providers @throws Exception @return array
[ "Compile", "the", "application", "service", "manifest", "file", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/ProviderRepository.php#L115-L149
train
themosis/framework
src/Core/ProviderRepository.php
ProviderRepository.writeManifest
public function writeManifest(array $manifest) { if (! is_writable(dirname($this->manifestPath))) { throw new Exception('The bootstrap/cache directory must be present and writable.'); } $this->files->put( $this->manifestPath, '<?php return '.var_export($manifest, true).';' ); return array_merge(['when' => []], $manifest); }
php
public function writeManifest(array $manifest) { if (! is_writable(dirname($this->manifestPath))) { throw new Exception('The bootstrap/cache directory must be present and writable.'); } $this->files->put( $this->manifestPath, '<?php return '.var_export($manifest, true).';' ); return array_merge(['when' => []], $manifest); }
[ "public", "function", "writeManifest", "(", "array", "$", "manifest", ")", "{", "if", "(", "!", "is_writable", "(", "dirname", "(", "$", "this", "->", "manifestPath", ")", ")", ")", "{", "throw", "new", "Exception", "(", "'The bootstrap/cache directory must be present and writable.'", ")", ";", "}", "$", "this", "->", "files", "->", "put", "(", "$", "this", "->", "manifestPath", ",", "'<?php return '", ".", "var_export", "(", "$", "manifest", ",", "true", ")", ".", "';'", ")", ";", "return", "array_merge", "(", "[", "'when'", "=>", "[", "]", "]", ",", "$", "manifest", ")", ";", "}" ]
Write the service manifest file. @param array $manifest @throws Exception @return array
[ "Write", "the", "service", "manifest", "file", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/ProviderRepository.php#L172-L184
train
themosis/framework
src/Forms/Transformers/NumberToLocalizedStringTransformer.php
NumberToLocalizedStringTransformer.transform
public function transform($data) { if (is_null($data) || '' === $data) { return ''; } if (! is_numeric($data)) { throw new DataTransformerException('A numeric value is expected.'); } $formatter = $this->getFormatter(); $value = $formatter->format($data); if (intl_is_failure($formatter->getErrorCode())) { throw new DataTransformerException($formatter->getErrorMessage()); } // Convert fixed spaces to normal ones return str_replace("\xc2\xa0", ' ', $value); }
php
public function transform($data) { if (is_null($data) || '' === $data) { return ''; } if (! is_numeric($data)) { throw new DataTransformerException('A numeric value is expected.'); } $formatter = $this->getFormatter(); $value = $formatter->format($data); if (intl_is_failure($formatter->getErrorCode())) { throw new DataTransformerException($formatter->getErrorMessage()); } // Convert fixed spaces to normal ones return str_replace("\xc2\xa0", ' ', $value); }
[ "public", "function", "transform", "(", "$", "data", ")", "{", "if", "(", "is_null", "(", "$", "data", ")", "||", "''", "===", "$", "data", ")", "{", "return", "''", ";", "}", "if", "(", "!", "is_numeric", "(", "$", "data", ")", ")", "{", "throw", "new", "DataTransformerException", "(", "'A numeric value is expected.'", ")", ";", "}", "$", "formatter", "=", "$", "this", "->", "getFormatter", "(", ")", ";", "$", "value", "=", "$", "formatter", "->", "format", "(", "$", "data", ")", ";", "if", "(", "intl_is_failure", "(", "$", "formatter", "->", "getErrorCode", "(", ")", ")", ")", "{", "throw", "new", "DataTransformerException", "(", "$", "formatter", "->", "getErrorMessage", "(", ")", ")", ";", "}", "// Convert fixed spaces to normal ones", "return", "str_replace", "(", "\"\\xc2\\xa0\"", ",", "' '", ",", "$", "value", ")", ";", "}" ]
Convert a numeric value to a localized string. @param int|float $data @throws DataTransformerException @return string
[ "Convert", "a", "numeric", "value", "to", "a", "localized", "string", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/Transformers/NumberToLocalizedStringTransformer.php#L38-L58
train
themosis/framework
src/Forms/Transformers/NumberToLocalizedStringTransformer.php
NumberToLocalizedStringTransformer.reverseTransform
public function reverseTransform($data) { if (is_null($data) || empty($data)) { return ''; } $formatter = $this->getFormatter(); $value = $formatter->parse($data); if (intl_is_failure($formatter->getErrorCode())) { throw new DataTransformerException($formatter->getErrorMessage()); } return $value; }
php
public function reverseTransform($data) { if (is_null($data) || empty($data)) { return ''; } $formatter = $this->getFormatter(); $value = $formatter->parse($data); if (intl_is_failure($formatter->getErrorCode())) { throw new DataTransformerException($formatter->getErrorMessage()); } return $value; }
[ "public", "function", "reverseTransform", "(", "$", "data", ")", "{", "if", "(", "is_null", "(", "$", "data", ")", "||", "empty", "(", "$", "data", ")", ")", "{", "return", "''", ";", "}", "$", "formatter", "=", "$", "this", "->", "getFormatter", "(", ")", ";", "$", "value", "=", "$", "formatter", "->", "parse", "(", "$", "data", ")", ";", "if", "(", "intl_is_failure", "(", "$", "formatter", "->", "getErrorCode", "(", ")", ")", ")", "{", "throw", "new", "DataTransformerException", "(", "$", "formatter", "->", "getErrorMessage", "(", ")", ")", ";", "}", "return", "$", "value", ";", "}" ]
Convert a localized string to a numeric value. @param string $data @throws DataTransformerException @return int|float
[ "Convert", "a", "localized", "string", "to", "a", "numeric", "value", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/Transformers/NumberToLocalizedStringTransformer.php#L69-L84
train
themosis/framework
src/Forms/Transformers/NumberToLocalizedStringTransformer.php
NumberToLocalizedStringTransformer.getFormatter
protected function getFormatter() { $formatter = new \NumberFormatter($this->locale, \NumberFormatter::DECIMAL); $precision = $this->field->getOption('precision', 0); if ($precision) { $formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $precision); } return $formatter; }
php
protected function getFormatter() { $formatter = new \NumberFormatter($this->locale, \NumberFormatter::DECIMAL); $precision = $this->field->getOption('precision', 0); if ($precision) { $formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $precision); } return $formatter; }
[ "protected", "function", "getFormatter", "(", ")", "{", "$", "formatter", "=", "new", "\\", "NumberFormatter", "(", "$", "this", "->", "locale", ",", "\\", "NumberFormatter", "::", "DECIMAL", ")", ";", "$", "precision", "=", "$", "this", "->", "field", "->", "getOption", "(", "'precision'", ",", "0", ")", ";", "if", "(", "$", "precision", ")", "{", "$", "formatter", "->", "setAttribute", "(", "\\", "NumberFormatter", "::", "FRACTION_DIGITS", ",", "$", "precision", ")", ";", "}", "return", "$", "formatter", ";", "}" ]
Retrieve a NumberFormatter instance. @return \NumberFormatter
[ "Retrieve", "a", "NumberFormatter", "instance", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/Transformers/NumberToLocalizedStringTransformer.php#L91-L101
train
themosis/framework
src/Taxonomy/TaxonomyField.php
TaxonomyField.make
public function make(TaxonomyInterface $taxonomy, array $options = []): TaxonomyField { $this->taxonomy = $taxonomy; $this->options = $options; return $this; }
php
public function make(TaxonomyInterface $taxonomy, array $options = []): TaxonomyField { $this->taxonomy = $taxonomy; $this->options = $options; return $this; }
[ "public", "function", "make", "(", "TaxonomyInterface", "$", "taxonomy", ",", "array", "$", "options", "=", "[", "]", ")", ":", "TaxonomyField", "{", "$", "this", "->", "taxonomy", "=", "$", "taxonomy", ";", "$", "this", "->", "options", "=", "$", "options", ";", "return", "$", "this", ";", "}" ]
Attach a taxonomy in order to add custom fields. @param TaxonomyInterface $taxonomy @param array $options @return TaxonomyField
[ "Attach", "a", "taxonomy", "in", "order", "to", "add", "custom", "fields", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Taxonomy/TaxonomyField.php#L65-L71
train
themosis/framework
src/Taxonomy/TaxonomyField.php
TaxonomyField.add
public function add(FieldTypeInterface $field): TaxonomyField { $field->setTheme('themosis.taxonomy'); $field->setPrefix($this->options['prefix'] ?? 'th_'); $this->repository->add($field); return $this; }
php
public function add(FieldTypeInterface $field): TaxonomyField { $field->setTheme('themosis.taxonomy'); $field->setPrefix($this->options['prefix'] ?? 'th_'); $this->repository->add($field); return $this; }
[ "public", "function", "add", "(", "FieldTypeInterface", "$", "field", ")", ":", "TaxonomyField", "{", "$", "field", "->", "setTheme", "(", "'themosis.taxonomy'", ")", ";", "$", "field", "->", "setPrefix", "(", "$", "this", "->", "options", "[", "'prefix'", "]", "??", "'th_'", ")", ";", "$", "this", "->", "repository", "->", "add", "(", "$", "field", ")", ";", "return", "$", "this", ";", "}" ]
Add a taxonomy custom field. @param FieldTypeInterface $field @return $this
[ "Add", "a", "taxonomy", "custom", "field", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Taxonomy/TaxonomyField.php#L80-L88
train
themosis/framework
src/Taxonomy/TaxonomyField.php
TaxonomyField.set
public function set() { // Register term meta on Rest API. if (function_exists('current_filter') && 'init' === current_filter()) { call_user_func($this->register()); } else { $this->action->add('init', $this->register()); } // Display fields. $this->action->add($this->taxonomy->getName().'_add_form_fields', $this->outputAddFields()); $this->action->add($this->taxonomy->getName().'_edit_form_fields', $this->outputEditFields()); // Save fields values. $this->action->add([ 'create_'.$this->taxonomy->getName(), 'edit_'.$this->taxonomy->getName() ], $this->save()); }
php
public function set() { // Register term meta on Rest API. if (function_exists('current_filter') && 'init' === current_filter()) { call_user_func($this->register()); } else { $this->action->add('init', $this->register()); } // Display fields. $this->action->add($this->taxonomy->getName().'_add_form_fields', $this->outputAddFields()); $this->action->add($this->taxonomy->getName().'_edit_form_fields', $this->outputEditFields()); // Save fields values. $this->action->add([ 'create_'.$this->taxonomy->getName(), 'edit_'.$this->taxonomy->getName() ], $this->save()); }
[ "public", "function", "set", "(", ")", "{", "// Register term meta on Rest API.", "if", "(", "function_exists", "(", "'current_filter'", ")", "&&", "'init'", "===", "current_filter", "(", ")", ")", "{", "call_user_func", "(", "$", "this", "->", "register", "(", ")", ")", ";", "}", "else", "{", "$", "this", "->", "action", "->", "add", "(", "'init'", ",", "$", "this", "->", "register", "(", ")", ")", ";", "}", "// Display fields.", "$", "this", "->", "action", "->", "add", "(", "$", "this", "->", "taxonomy", "->", "getName", "(", ")", ".", "'_add_form_fields'", ",", "$", "this", "->", "outputAddFields", "(", ")", ")", ";", "$", "this", "->", "action", "->", "add", "(", "$", "this", "->", "taxonomy", "->", "getName", "(", ")", ".", "'_edit_form_fields'", ",", "$", "this", "->", "outputEditFields", "(", ")", ")", ";", "// Save fields values.", "$", "this", "->", "action", "->", "add", "(", "[", "'create_'", ".", "$", "this", "->", "taxonomy", "->", "getName", "(", ")", ",", "'edit_'", ".", "$", "this", "->", "taxonomy", "->", "getName", "(", ")", "]", ",", "$", "this", "->", "save", "(", ")", ")", ";", "}" ]
Set taxonomy custom fields.
[ "Set", "taxonomy", "custom", "fields", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Taxonomy/TaxonomyField.php#L93-L111
train
themosis/framework
src/Taxonomy/TaxonomyField.php
TaxonomyField.register
protected function register() { return function () { foreach ($this->repository as $field) { register_meta('term', $field->getName(), [ 'type' => $field->getOption('data_type', 'string'), 'single' => ! $field->getOption('multiple', false), 'show_in_rest' => $field->getOption('show_in_rest', false), 'sanitize_callback' => $this->sanitize($field) ]); } }; }
php
protected function register() { return function () { foreach ($this->repository as $field) { register_meta('term', $field->getName(), [ 'type' => $field->getOption('data_type', 'string'), 'single' => ! $field->getOption('multiple', false), 'show_in_rest' => $field->getOption('show_in_rest', false), 'sanitize_callback' => $this->sanitize($field) ]); } }; }
[ "protected", "function", "register", "(", ")", "{", "return", "function", "(", ")", "{", "foreach", "(", "$", "this", "->", "repository", "as", "$", "field", ")", "{", "register_meta", "(", "'term'", ",", "$", "field", "->", "getName", "(", ")", ",", "[", "'type'", "=>", "$", "field", "->", "getOption", "(", "'data_type'", ",", "'string'", ")", ",", "'single'", "=>", "!", "$", "field", "->", "getOption", "(", "'multiple'", ",", "false", ")", ",", "'show_in_rest'", "=>", "$", "field", "->", "getOption", "(", "'show_in_rest'", ",", "false", ")", ",", "'sanitize_callback'", "=>", "$", "this", "->", "sanitize", "(", "$", "field", ")", "]", ")", ";", "}", "}", ";", "}" ]
Return the callback used to register term meta. @return \Closure
[ "Return", "the", "callback", "used", "to", "register", "term", "meta", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Taxonomy/TaxonomyField.php#L118-L130
train
themosis/framework
src/Taxonomy/TaxonomyField.php
TaxonomyField.sanitize
protected function sanitize(FieldTypeInterface $field) { return function ($value, $key, $type) use ($field) { $validator = $this->validator->make( [$key => $value], $this->getTermRules(), $this->getTermMessages(), $this->getTermPlaceholders() ); $validation = $validator->valid(); return $validation[$key] ?? null; }; }
php
protected function sanitize(FieldTypeInterface $field) { return function ($value, $key, $type) use ($field) { $validator = $this->validator->make( [$key => $value], $this->getTermRules(), $this->getTermMessages(), $this->getTermPlaceholders() ); $validation = $validator->valid(); return $validation[$key] ?? null; }; }
[ "protected", "function", "sanitize", "(", "FieldTypeInterface", "$", "field", ")", "{", "return", "function", "(", "$", "value", ",", "$", "key", ",", "$", "type", ")", "use", "(", "$", "field", ")", "{", "$", "validator", "=", "$", "this", "->", "validator", "->", "make", "(", "[", "$", "key", "=>", "$", "value", "]", ",", "$", "this", "->", "getTermRules", "(", ")", ",", "$", "this", "->", "getTermMessages", "(", ")", ",", "$", "this", "->", "getTermPlaceholders", "(", ")", ")", ";", "$", "validation", "=", "$", "validator", "->", "valid", "(", ")", ";", "return", "$", "validation", "[", "$", "key", "]", "??", "null", ";", "}", ";", "}" ]
Sanitize term meta value. @param FieldTypeInterface $field @return \Closure
[ "Sanitize", "term", "meta", "value", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Taxonomy/TaxonomyField.php#L139-L153
train
themosis/framework
src/Taxonomy/TaxonomyField.php
TaxonomyField.save
protected function save() { return function ($term_id) { /** @var Validator $validator */ $validator = $this->validator->make( $this->getTermData(app('request')), $this->getTermRules(), $this->getTermMessages(), $this->getTermPlaceholders() ); $validation = $validator->valid(); foreach ($this->repository->all() as $field) { /** @var FieldTypeInterface|BaseType|CanHandleTerms $field */ $field->setErrorMessageBag($validator->errors()); if (method_exists($field, 'termSave')) { $field->termSave($validation[$field->getName()] ?? null, $term_id); } else { throw new TaxonomyException( 'Unable to save ['.$field->getName().']. The [termSave] method is missing.' ); } } }; }
php
protected function save() { return function ($term_id) { /** @var Validator $validator */ $validator = $this->validator->make( $this->getTermData(app('request')), $this->getTermRules(), $this->getTermMessages(), $this->getTermPlaceholders() ); $validation = $validator->valid(); foreach ($this->repository->all() as $field) { /** @var FieldTypeInterface|BaseType|CanHandleTerms $field */ $field->setErrorMessageBag($validator->errors()); if (method_exists($field, 'termSave')) { $field->termSave($validation[$field->getName()] ?? null, $term_id); } else { throw new TaxonomyException( 'Unable to save ['.$field->getName().']. The [termSave] method is missing.' ); } } }; }
[ "protected", "function", "save", "(", ")", "{", "return", "function", "(", "$", "term_id", ")", "{", "/** @var Validator $validator */", "$", "validator", "=", "$", "this", "->", "validator", "->", "make", "(", "$", "this", "->", "getTermData", "(", "app", "(", "'request'", ")", ")", ",", "$", "this", "->", "getTermRules", "(", ")", ",", "$", "this", "->", "getTermMessages", "(", ")", ",", "$", "this", "->", "getTermPlaceholders", "(", ")", ")", ";", "$", "validation", "=", "$", "validator", "->", "valid", "(", ")", ";", "foreach", "(", "$", "this", "->", "repository", "->", "all", "(", ")", "as", "$", "field", ")", "{", "/** @var FieldTypeInterface|BaseType|CanHandleTerms $field */", "$", "field", "->", "setErrorMessageBag", "(", "$", "validator", "->", "errors", "(", ")", ")", ";", "if", "(", "method_exists", "(", "$", "field", ",", "'termSave'", ")", ")", "{", "$", "field", "->", "termSave", "(", "$", "validation", "[", "$", "field", "->", "getName", "(", ")", "]", "??", "null", ",", "$", "term_id", ")", ";", "}", "else", "{", "throw", "new", "TaxonomyException", "(", "'Unable to save ['", ".", "$", "field", "->", "getName", "(", ")", ".", "']. The [termSave] method is missing.'", ")", ";", "}", "}", "}", ";", "}" ]
Return the function managing term meta registration. @return \Closure
[ "Return", "the", "function", "managing", "term", "meta", "registration", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Taxonomy/TaxonomyField.php#L160-L186
train
themosis/framework
src/Taxonomy/TaxonomyField.php
TaxonomyField.getTermData
protected function getTermData(Request $request) { $data = []; foreach ($this->repository as $field) { $data[$field->getName()] = $request->get($field->getName()); } return $data; }
php
protected function getTermData(Request $request) { $data = []; foreach ($this->repository as $field) { $data[$field->getName()] = $request->get($field->getName()); } return $data; }
[ "protected", "function", "getTermData", "(", "Request", "$", "request", ")", "{", "$", "data", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "repository", "as", "$", "field", ")", "{", "$", "data", "[", "$", "field", "->", "getName", "(", ")", "]", "=", "$", "request", "->", "get", "(", "$", "field", "->", "getName", "(", ")", ")", ";", "}", "return", "$", "data", ";", "}" ]
Fetch raw data from the request. @param Request $request @return array
[ "Fetch", "raw", "data", "from", "the", "request", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Taxonomy/TaxonomyField.php#L195-L204
train
themosis/framework
src/Taxonomy/TaxonomyField.php
TaxonomyField.getTermRules
protected function getTermRules() { $rules = []; foreach ($this->repository as $field) { $rules[$field->getName()] = $field->getOption('rules'); } return $rules; }
php
protected function getTermRules() { $rules = []; foreach ($this->repository as $field) { $rules[$field->getName()] = $field->getOption('rules'); } return $rules; }
[ "protected", "function", "getTermRules", "(", ")", "{", "$", "rules", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "repository", "as", "$", "field", ")", "{", "$", "rules", "[", "$", "field", "->", "getName", "(", ")", "]", "=", "$", "field", "->", "getOption", "(", "'rules'", ")", ";", "}", "return", "$", "rules", ";", "}" ]
Return terms rules. @return array
[ "Return", "terms", "rules", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Taxonomy/TaxonomyField.php#L211-L220
train
themosis/framework
src/Taxonomy/TaxonomyField.php
TaxonomyField.getTermMessages
protected function getTermMessages() { $messages = []; foreach ($this->repository as $field) { foreach ($field->getOption('messages') as $rule => $message) { $messages[$field->getName().'.'.$rule] = $message; } } return $messages; }
php
protected function getTermMessages() { $messages = []; foreach ($this->repository as $field) { foreach ($field->getOption('messages') as $rule => $message) { $messages[$field->getName().'.'.$rule] = $message; } } return $messages; }
[ "protected", "function", "getTermMessages", "(", ")", "{", "$", "messages", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "repository", "as", "$", "field", ")", "{", "foreach", "(", "$", "field", "->", "getOption", "(", "'messages'", ")", "as", "$", "rule", "=>", "$", "message", ")", "{", "$", "messages", "[", "$", "field", "->", "getName", "(", ")", ".", "'.'", ".", "$", "rule", "]", "=", "$", "message", ";", "}", "}", "return", "$", "messages", ";", "}" ]
Return terms errors messages. @return array
[ "Return", "terms", "errors", "messages", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Taxonomy/TaxonomyField.php#L227-L238
train
themosis/framework
src/Taxonomy/TaxonomyField.php
TaxonomyField.getTermPlaceholders
protected function getTermPlaceholders() { $placeholders = []; foreach ($this->repository as $field) { $placeholders[$field->getName()] = $field->getOption('placeholder'); } return $placeholders; }
php
protected function getTermPlaceholders() { $placeholders = []; foreach ($this->repository as $field) { $placeholders[$field->getName()] = $field->getOption('placeholder'); } return $placeholders; }
[ "protected", "function", "getTermPlaceholders", "(", ")", "{", "$", "placeholders", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "repository", "as", "$", "field", ")", "{", "$", "placeholders", "[", "$", "field", "->", "getName", "(", ")", "]", "=", "$", "field", "->", "getOption", "(", "'placeholder'", ")", ";", "}", "return", "$", "placeholders", ";", "}" ]
Return terms placeholders. @return array
[ "Return", "terms", "placeholders", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Taxonomy/TaxonomyField.php#L245-L254
train
themosis/framework
src/Taxonomy/TaxonomyField.php
TaxonomyField.outputEditFields
protected function outputEditFields() { return function ($term) { /** @var \WP_Term $term */ foreach ($this->repository as $field) { if (method_exists($field, 'termGet')) { $field->termGet($term->term_id); } } echo $this->factory->make('themosis.taxonomy.edit', [ 'fields' => $this->repository ])->render(); }; }
php
protected function outputEditFields() { return function ($term) { /** @var \WP_Term $term */ foreach ($this->repository as $field) { if (method_exists($field, 'termGet')) { $field->termGet($term->term_id); } } echo $this->factory->make('themosis.taxonomy.edit', [ 'fields' => $this->repository ])->render(); }; }
[ "protected", "function", "outputEditFields", "(", ")", "{", "return", "function", "(", "$", "term", ")", "{", "/** @var \\WP_Term $term */", "foreach", "(", "$", "this", "->", "repository", "as", "$", "field", ")", "{", "if", "(", "method_exists", "(", "$", "field", ",", "'termGet'", ")", ")", "{", "$", "field", "->", "termGet", "(", "$", "term", "->", "term_id", ")", ";", "}", "}", "echo", "$", "this", "->", "factory", "->", "make", "(", "'themosis.taxonomy.edit'", ",", "[", "'fields'", "=>", "$", "this", "->", "repository", "]", ")", "->", "render", "(", ")", ";", "}", ";", "}" ]
Handle display of fields on "edit" term screen. @return \Closure
[ "Handle", "display", "of", "fields", "on", "edit", "term", "screen", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Taxonomy/TaxonomyField.php#L275-L289
train
themosis/framework
src/Forms/Fields/Types/ButtonType.php
ButtonType.getDefaultOptions
public function getDefaultOptions(): array { $options = parent::getDefaultOptions(); // Check the "type" attribute. If it is not set, // let's define it by default to "submit". if (! isset($options['attributes']['type'])) { $options['attributes']['type'] = 'submit'; } // By default, disable button field type to be mapped // to a data object. $options['mapped'] = false; return $options; }
php
public function getDefaultOptions(): array { $options = parent::getDefaultOptions(); // Check the "type" attribute. If it is not set, // let's define it by default to "submit". if (! isset($options['attributes']['type'])) { $options['attributes']['type'] = 'submit'; } // By default, disable button field type to be mapped // to a data object. $options['mapped'] = false; return $options; }
[ "public", "function", "getDefaultOptions", "(", ")", ":", "array", "{", "$", "options", "=", "parent", "::", "getDefaultOptions", "(", ")", ";", "// Check the \"type\" attribute. If it is not set,", "// let's define it by default to \"submit\".", "if", "(", "!", "isset", "(", "$", "options", "[", "'attributes'", "]", "[", "'type'", "]", ")", ")", "{", "$", "options", "[", "'attributes'", "]", "[", "'type'", "]", "=", "'submit'", ";", "}", "// By default, disable button field type to be mapped", "// to a data object.", "$", "options", "[", "'mapped'", "]", "=", "false", ";", "return", "$", "options", ";", "}" ]
Get default button options. @return array
[ "Get", "default", "button", "options", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/Fields/Types/ButtonType.php#L35-L50
train
themosis/framework
src/Metabox/Factory.php
Factory.make
public function make(string $id, $screen = 'post'): MetaboxInterface { $metabox = (new Metabox($id, $this->action, $this->filter, new FieldsRepository())) ->setContainer($this->container) ->setTitle($this->setDefaultTitle($id)) ->setScreen($screen) ->setContext('normal') ->setPriority('default') ->setArguments([ '__block_editor_compatible_meta_box' => true, '__back_compat_meta_box' => false ]) ->setResource($this->resource) ->setLocale($this->container->getLocale()); $this->setMetaboxTranslations($metabox); $abstract = sprintf('themosis.metabox.%s', $id); if (! $this->container->bound($abstract)) { $this->container->instance($abstract, $metabox); } else { throw new MetaboxException('The metabox with an ID of ['.$id.'] is already bound.'); } return $metabox; }
php
public function make(string $id, $screen = 'post'): MetaboxInterface { $metabox = (new Metabox($id, $this->action, $this->filter, new FieldsRepository())) ->setContainer($this->container) ->setTitle($this->setDefaultTitle($id)) ->setScreen($screen) ->setContext('normal') ->setPriority('default') ->setArguments([ '__block_editor_compatible_meta_box' => true, '__back_compat_meta_box' => false ]) ->setResource($this->resource) ->setLocale($this->container->getLocale()); $this->setMetaboxTranslations($metabox); $abstract = sprintf('themosis.metabox.%s', $id); if (! $this->container->bound($abstract)) { $this->container->instance($abstract, $metabox); } else { throw new MetaboxException('The metabox with an ID of ['.$id.'] is already bound.'); } return $metabox; }
[ "public", "function", "make", "(", "string", "$", "id", ",", "$", "screen", "=", "'post'", ")", ":", "MetaboxInterface", "{", "$", "metabox", "=", "(", "new", "Metabox", "(", "$", "id", ",", "$", "this", "->", "action", ",", "$", "this", "->", "filter", ",", "new", "FieldsRepository", "(", ")", ")", ")", "->", "setContainer", "(", "$", "this", "->", "container", ")", "->", "setTitle", "(", "$", "this", "->", "setDefaultTitle", "(", "$", "id", ")", ")", "->", "setScreen", "(", "$", "screen", ")", "->", "setContext", "(", "'normal'", ")", "->", "setPriority", "(", "'default'", ")", "->", "setArguments", "(", "[", "'__block_editor_compatible_meta_box'", "=>", "true", ",", "'__back_compat_meta_box'", "=>", "false", "]", ")", "->", "setResource", "(", "$", "this", "->", "resource", ")", "->", "setLocale", "(", "$", "this", "->", "container", "->", "getLocale", "(", ")", ")", ";", "$", "this", "->", "setMetaboxTranslations", "(", "$", "metabox", ")", ";", "$", "abstract", "=", "sprintf", "(", "'themosis.metabox.%s'", ",", "$", "id", ")", ";", "if", "(", "!", "$", "this", "->", "container", "->", "bound", "(", "$", "abstract", ")", ")", "{", "$", "this", "->", "container", "->", "instance", "(", "$", "abstract", ",", "$", "metabox", ")", ";", "}", "else", "{", "throw", "new", "MetaboxException", "(", "'The metabox with an ID of ['", ".", "$", "id", ".", "'] is already bound.'", ")", ";", "}", "return", "$", "metabox", ";", "}" ]
Create a new metabox instance. @param string $id @param string|array|\WP_Screen $screen @throws MetaboxException @return MetaboxInterface
[ "Create", "a", "new", "metabox", "instance", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Metabox/Factory.php#L55-L81
train
themosis/framework
src/Metabox/Factory.php
Factory.setMetaboxTranslations
protected function setMetaboxTranslations(MetaboxInterface $metabox) { if (! function_exists('__')) { return $this; } $metabox->addTranslation('done', __('Saved', Application::TEXTDOMAIN)); $metabox->addTranslation('error', __('Saved with errors', Application::TEXTDOMAIN)); $metabox->addTranslation('saving', __('Saving', Application::TEXTDOMAIN)); $metabox->addTranslation('submit', sprintf('%s %s', __('Save', Application::TEXTDOMAIN), $metabox->getTitle())); return $this; }
php
protected function setMetaboxTranslations(MetaboxInterface $metabox) { if (! function_exists('__')) { return $this; } $metabox->addTranslation('done', __('Saved', Application::TEXTDOMAIN)); $metabox->addTranslation('error', __('Saved with errors', Application::TEXTDOMAIN)); $metabox->addTranslation('saving', __('Saving', Application::TEXTDOMAIN)); $metabox->addTranslation('submit', sprintf('%s %s', __('Save', Application::TEXTDOMAIN), $metabox->getTitle())); return $this; }
[ "protected", "function", "setMetaboxTranslations", "(", "MetaboxInterface", "$", "metabox", ")", "{", "if", "(", "!", "function_exists", "(", "'__'", ")", ")", "{", "return", "$", "this", ";", "}", "$", "metabox", "->", "addTranslation", "(", "'done'", ",", "__", "(", "'Saved'", ",", "Application", "::", "TEXTDOMAIN", ")", ")", ";", "$", "metabox", "->", "addTranslation", "(", "'error'", ",", "__", "(", "'Saved with errors'", ",", "Application", "::", "TEXTDOMAIN", ")", ")", ";", "$", "metabox", "->", "addTranslation", "(", "'saving'", ",", "__", "(", "'Saving'", ",", "Application", "::", "TEXTDOMAIN", ")", ")", ";", "$", "metabox", "->", "addTranslation", "(", "'submit'", ",", "sprintf", "(", "'%s %s'", ",", "__", "(", "'Save'", ",", "Application", "::", "TEXTDOMAIN", ")", ",", "$", "metabox", "->", "getTitle", "(", ")", ")", ")", ";", "return", "$", "this", ";", "}" ]
Set metabox translations strings. @param MetaboxInterface $metabox @return $this
[ "Set", "metabox", "translations", "strings", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Metabox/Factory.php#L102-L114
train
themosis/framework
src/Page/Page.php
Page.set
public function set(): PageInterface { $hook = $this->isNetwork() ? 'network_admin_menu' : 'admin_menu'; // Action for page display. $this->action->add($hook, [$this, 'build']); // Action for page settings. $this->action->add('admin_init', [$this, 'configureSettings']); return $this; }
php
public function set(): PageInterface { $hook = $this->isNetwork() ? 'network_admin_menu' : 'admin_menu'; // Action for page display. $this->action->add($hook, [$this, 'build']); // Action for page settings. $this->action->add('admin_init', [$this, 'configureSettings']); return $this; }
[ "public", "function", "set", "(", ")", ":", "PageInterface", "{", "$", "hook", "=", "$", "this", "->", "isNetwork", "(", ")", "?", "'network_admin_menu'", ":", "'admin_menu'", ";", "// Action for page display.", "$", "this", "->", "action", "->", "add", "(", "$", "hook", ",", "[", "$", "this", ",", "'build'", "]", ")", ";", "// Action for page settings.", "$", "this", "->", "action", "->", "add", "(", "'admin_init'", ",", "[", "$", "this", ",", "'configureSettings'", "]", ")", ";", "return", "$", "this", ";", "}" ]
Set the page. Display it on the WordPress administration. @return PageInterface
[ "Set", "the", "page", ".", "Display", "it", "on", "the", "WordPress", "administration", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Page/Page.php#L358-L368
train
themosis/framework
src/Page/Page.php
Page.findParentHook
protected function findParentHook(): string { if (! $this->hasParent()) { return ''; } // Check if parent attribute is attached to a custom post type or another page. if (false !== $pos = strpos($this->getParent(), 'post_type=')) { // Parent hook is equivalent to the post type slug value. return substr($this->getParent(), $pos + 10); } elseif ('edit.php' === trim($this->getParent(), '\/?&')) { // Parent is the default post post type. return 'posts'; } // The current page is attached to another one. $abstract = 'page.'.$this->getParent(); if ($this->ui()->factory()->getContainer()->bound($abstract)) { // Parent hook is equivalent to the page menu as lowercase. $parent = $this->ui()->factory()->getContainer()->make($abstract); return strtolower($parent->getMenu()); } return ''; }
php
protected function findParentHook(): string { if (! $this->hasParent()) { return ''; } // Check if parent attribute is attached to a custom post type or another page. if (false !== $pos = strpos($this->getParent(), 'post_type=')) { // Parent hook is equivalent to the post type slug value. return substr($this->getParent(), $pos + 10); } elseif ('edit.php' === trim($this->getParent(), '\/?&')) { // Parent is the default post post type. return 'posts'; } // The current page is attached to another one. $abstract = 'page.'.$this->getParent(); if ($this->ui()->factory()->getContainer()->bound($abstract)) { // Parent hook is equivalent to the page menu as lowercase. $parent = $this->ui()->factory()->getContainer()->make($abstract); return strtolower($parent->getMenu()); } return ''; }
[ "protected", "function", "findParentHook", "(", ")", ":", "string", "{", "if", "(", "!", "$", "this", "->", "hasParent", "(", ")", ")", "{", "return", "''", ";", "}", "// Check if parent attribute is attached to a custom post type or another page.", "if", "(", "false", "!==", "$", "pos", "=", "strpos", "(", "$", "this", "->", "getParent", "(", ")", ",", "'post_type='", ")", ")", "{", "// Parent hook is equivalent to the post type slug value.", "return", "substr", "(", "$", "this", "->", "getParent", "(", ")", ",", "$", "pos", "+", "10", ")", ";", "}", "elseif", "(", "'edit.php'", "===", "trim", "(", "$", "this", "->", "getParent", "(", ")", ",", "'\\/?&'", ")", ")", "{", "// Parent is the default post post type.", "return", "'posts'", ";", "}", "// The current page is attached to another one.", "$", "abstract", "=", "'page.'", ".", "$", "this", "->", "getParent", "(", ")", ";", "if", "(", "$", "this", "->", "ui", "(", ")", "->", "factory", "(", ")", "->", "getContainer", "(", ")", "->", "bound", "(", "$", "abstract", ")", ")", "{", "// Parent hook is equivalent to the page menu as lowercase.", "$", "parent", "=", "$", "this", "->", "ui", "(", ")", "->", "factory", "(", ")", "->", "getContainer", "(", ")", "->", "make", "(", "$", "abstract", ")", ";", "return", "strtolower", "(", "$", "parent", "->", "getMenu", "(", ")", ")", ";", "}", "return", "''", ";", "}" ]
Find the page parent hook if any. @return string
[ "Find", "the", "page", "parent", "hook", "if", "any", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Page/Page.php#L375-L401
train
themosis/framework
src/Page/Page.php
Page.build
public function build() { if (is_null($this->getParent())) { // Add a top menu page. add_menu_page( $this->getTitle(), $this->getMenu(), $this->getCapability(), $this->getSlug(), [$this, 'render'], $this->getIcon(), $this->getPosition() ); } else { // Add a submenu page. add_submenu_page( $this->getParent(), $this->getTitle(), $this->getMenu(), $this->getCapability(), $this->getSlug(), [$this, 'render'] ); } }
php
public function build() { if (is_null($this->getParent())) { // Add a top menu page. add_menu_page( $this->getTitle(), $this->getMenu(), $this->getCapability(), $this->getSlug(), [$this, 'render'], $this->getIcon(), $this->getPosition() ); } else { // Add a submenu page. add_submenu_page( $this->getParent(), $this->getTitle(), $this->getMenu(), $this->getCapability(), $this->getSlug(), [$this, 'render'] ); } }
[ "public", "function", "build", "(", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "getParent", "(", ")", ")", ")", "{", "// Add a top menu page.", "add_menu_page", "(", "$", "this", "->", "getTitle", "(", ")", ",", "$", "this", "->", "getMenu", "(", ")", ",", "$", "this", "->", "getCapability", "(", ")", ",", "$", "this", "->", "getSlug", "(", ")", ",", "[", "$", "this", ",", "'render'", "]", ",", "$", "this", "->", "getIcon", "(", ")", ",", "$", "this", "->", "getPosition", "(", ")", ")", ";", "}", "else", "{", "// Add a submenu page.", "add_submenu_page", "(", "$", "this", "->", "getParent", "(", ")", ",", "$", "this", "->", "getTitle", "(", ")", ",", "$", "this", "->", "getMenu", "(", ")", ",", "$", "this", "->", "getCapability", "(", ")", ",", "$", "this", "->", "getSlug", "(", ")", ",", "[", "$", "this", ",", "'render'", "]", ")", ";", "}", "}" ]
Build the WordPress pages.
[ "Build", "the", "WordPress", "pages", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Page/Page.php#L406-L430
train
themosis/framework
src/Page/Page.php
Page.with
public function with($key, $value = null): PageInterface { $this->ui()->getView()->with($key, $value); return $this; }
php
public function with($key, $value = null): PageInterface { $this->ui()->getView()->with($key, $value); return $this; }
[ "public", "function", "with", "(", "$", "key", ",", "$", "value", "=", "null", ")", ":", "PageInterface", "{", "$", "this", "->", "ui", "(", ")", "->", "getView", "(", ")", "->", "with", "(", "$", "key", ",", "$", "value", ")", ";", "return", "$", "this", ";", "}" ]
Add data to the page view. @param string|array $key @param mixed $value @return PageInterface
[ "Add", "data", "to", "the", "page", "view", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Page/Page.php#L460-L465
train
themosis/framework
src/Page/Page.php
Page.addSections
public function addSections(array $sections): PageInterface { $sections = array_merge( $this->repository()->getSections()->all(), $sections ); array_walk($sections, function ($section) { // Set a default view to each section if none defined. /** @var SectionInterface $section */ if (empty($section->getView())) { $section->setView('section'); } }); $this->repository()->setSections($sections); return $this; }
php
public function addSections(array $sections): PageInterface { $sections = array_merge( $this->repository()->getSections()->all(), $sections ); array_walk($sections, function ($section) { // Set a default view to each section if none defined. /** @var SectionInterface $section */ if (empty($section->getView())) { $section->setView('section'); } }); $this->repository()->setSections($sections); return $this; }
[ "public", "function", "addSections", "(", "array", "$", "sections", ")", ":", "PageInterface", "{", "$", "sections", "=", "array_merge", "(", "$", "this", "->", "repository", "(", ")", "->", "getSections", "(", ")", "->", "all", "(", ")", ",", "$", "sections", ")", ";", "array_walk", "(", "$", "sections", ",", "function", "(", "$", "section", ")", "{", "// Set a default view to each section if none defined.", "/** @var SectionInterface $section */", "if", "(", "empty", "(", "$", "section", "->", "getView", "(", ")", ")", ")", "{", "$", "section", "->", "setView", "(", "'section'", ")", ";", "}", "}", ")", ";", "$", "this", "->", "repository", "(", ")", "->", "setSections", "(", "$", "sections", ")", ";", "return", "$", "this", ";", "}" ]
Add sections to the page. @param array $sections @return PageInterface
[ "Add", "sections", "to", "the", "page", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Page/Page.php#L484-L502
train
themosis/framework
src/Page/Page.php
Page.addSettings
public function addSettings($section, array $settings = []): PageInterface { $currentSettings = $this->repository()->getSettings()->all(); if (is_array($section)) { $settings = array_merge($currentSettings, $section); } else { $settings = array_merge($currentSettings, [$section => $settings]); } $this->repository()->setSettings($settings); // Set a default page view for handling // the settings. A user can still overwrite // the view. if ('page' === $this->ui()->getViewPath()) { $this->ui()->setView('options'); } return $this; }
php
public function addSettings($section, array $settings = []): PageInterface { $currentSettings = $this->repository()->getSettings()->all(); if (is_array($section)) { $settings = array_merge($currentSettings, $section); } else { $settings = array_merge($currentSettings, [$section => $settings]); } $this->repository()->setSettings($settings); // Set a default page view for handling // the settings. A user can still overwrite // the view. if ('page' === $this->ui()->getViewPath()) { $this->ui()->setView('options'); } return $this; }
[ "public", "function", "addSettings", "(", "$", "section", ",", "array", "$", "settings", "=", "[", "]", ")", ":", "PageInterface", "{", "$", "currentSettings", "=", "$", "this", "->", "repository", "(", ")", "->", "getSettings", "(", ")", "->", "all", "(", ")", ";", "if", "(", "is_array", "(", "$", "section", ")", ")", "{", "$", "settings", "=", "array_merge", "(", "$", "currentSettings", ",", "$", "section", ")", ";", "}", "else", "{", "$", "settings", "=", "array_merge", "(", "$", "currentSettings", ",", "[", "$", "section", "=>", "$", "settings", "]", ")", ";", "}", "$", "this", "->", "repository", "(", ")", "->", "setSettings", "(", "$", "settings", ")", ";", "// Set a default page view for handling", "// the settings. A user can still overwrite", "// the view.", "if", "(", "'page'", "===", "$", "this", "->", "ui", "(", ")", "->", "getViewPath", "(", ")", ")", "{", "$", "this", "->", "ui", "(", ")", "->", "setView", "(", "'options'", ")", ";", "}", "return", "$", "this", ";", "}" ]
Add settings to the page. @param string|array $section @param array $settings @return PageInterface
[ "Add", "settings", "to", "the", "page", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Page/Page.php#L512-L532
train
themosis/framework
src/Page/Page.php
Page.setPrefix
public function setPrefix(string $prefix): PageInterface { $this->prefix = $prefix; $this->repository()->getSettings()->collapse()->each(function ($setting) use ($prefix) { /** @var $setting FieldTypeInterface */ $setting->setPrefix($prefix); }); return $this; }
php
public function setPrefix(string $prefix): PageInterface { $this->prefix = $prefix; $this->repository()->getSettings()->collapse()->each(function ($setting) use ($prefix) { /** @var $setting FieldTypeInterface */ $setting->setPrefix($prefix); }); return $this; }
[ "public", "function", "setPrefix", "(", "string", "$", "prefix", ")", ":", "PageInterface", "{", "$", "this", "->", "prefix", "=", "$", "prefix", ";", "$", "this", "->", "repository", "(", ")", "->", "getSettings", "(", ")", "->", "collapse", "(", ")", "->", "each", "(", "function", "(", "$", "setting", ")", "use", "(", "$", "prefix", ")", "{", "/** @var $setting FieldTypeInterface */", "$", "setting", "->", "setPrefix", "(", "$", "prefix", ")", ";", "}", ")", ";", "return", "$", "this", ";", "}" ]
Set the page settings name prefix. @param string $prefix @return PageInterface
[ "Set", "the", "page", "settings", "name", "prefix", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Page/Page.php#L551-L561
train
themosis/framework
src/Page/Page.php
Page.configureSettings
public function configureSettings() { // If no settings && sections, return. $settings = $this->repository()->getSettings(); $sections = $this->repository()->getSections(); if ($settings->isEmpty() && $sections->isEmpty()) { return; } // Configure sections. $sections->each(function ($section) { /** @var SectionInterface $section */ add_settings_section($section->getId(), $section->getTitle(), [$this, 'renderSections'], $this->getSlug()); }); // Configure settings. foreach ($settings->all() as $slug => $fields) { foreach ($fields as $setting) { $setting = $this->prepareSetting($setting); // Display the setting. add_settings_field( $setting->getName(), $setting->getOption('label'), [$this, 'renderSettings'], $this->getSlug(), $slug, $setting ); // Validate setting. $showInRest = $this->isShownInRest(); if ($setting->getOption('show_in_rest', false)) { $showInRest = true; } register_setting($this->getSlug(), $setting->getName(), [ 'sanitize_callback' => [$this, 'sanitizeSetting'], 'default' => $setting->getOption('data', ''), 'show_in_rest' => $showInRest, 'type' => $setting->getOption('data_type', 'string') ]); } } }
php
public function configureSettings() { // If no settings && sections, return. $settings = $this->repository()->getSettings(); $sections = $this->repository()->getSections(); if ($settings->isEmpty() && $sections->isEmpty()) { return; } // Configure sections. $sections->each(function ($section) { /** @var SectionInterface $section */ add_settings_section($section->getId(), $section->getTitle(), [$this, 'renderSections'], $this->getSlug()); }); // Configure settings. foreach ($settings->all() as $slug => $fields) { foreach ($fields as $setting) { $setting = $this->prepareSetting($setting); // Display the setting. add_settings_field( $setting->getName(), $setting->getOption('label'), [$this, 'renderSettings'], $this->getSlug(), $slug, $setting ); // Validate setting. $showInRest = $this->isShownInRest(); if ($setting->getOption('show_in_rest', false)) { $showInRest = true; } register_setting($this->getSlug(), $setting->getName(), [ 'sanitize_callback' => [$this, 'sanitizeSetting'], 'default' => $setting->getOption('data', ''), 'show_in_rest' => $showInRest, 'type' => $setting->getOption('data_type', 'string') ]); } } }
[ "public", "function", "configureSettings", "(", ")", "{", "// If no settings && sections, return.", "$", "settings", "=", "$", "this", "->", "repository", "(", ")", "->", "getSettings", "(", ")", ";", "$", "sections", "=", "$", "this", "->", "repository", "(", ")", "->", "getSections", "(", ")", ";", "if", "(", "$", "settings", "->", "isEmpty", "(", ")", "&&", "$", "sections", "->", "isEmpty", "(", ")", ")", "{", "return", ";", "}", "// Configure sections.", "$", "sections", "->", "each", "(", "function", "(", "$", "section", ")", "{", "/** @var SectionInterface $section */", "add_settings_section", "(", "$", "section", "->", "getId", "(", ")", ",", "$", "section", "->", "getTitle", "(", ")", ",", "[", "$", "this", ",", "'renderSections'", "]", ",", "$", "this", "->", "getSlug", "(", ")", ")", ";", "}", ")", ";", "// Configure settings.", "foreach", "(", "$", "settings", "->", "all", "(", ")", "as", "$", "slug", "=>", "$", "fields", ")", "{", "foreach", "(", "$", "fields", "as", "$", "setting", ")", "{", "$", "setting", "=", "$", "this", "->", "prepareSetting", "(", "$", "setting", ")", ";", "// Display the setting.", "add_settings_field", "(", "$", "setting", "->", "getName", "(", ")", ",", "$", "setting", "->", "getOption", "(", "'label'", ")", ",", "[", "$", "this", ",", "'renderSettings'", "]", ",", "$", "this", "->", "getSlug", "(", ")", ",", "$", "slug", ",", "$", "setting", ")", ";", "// Validate setting.", "$", "showInRest", "=", "$", "this", "->", "isShownInRest", "(", ")", ";", "if", "(", "$", "setting", "->", "getOption", "(", "'show_in_rest'", ",", "false", ")", ")", "{", "$", "showInRest", "=", "true", ";", "}", "register_setting", "(", "$", "this", "->", "getSlug", "(", ")", ",", "$", "setting", "->", "getName", "(", ")", ",", "[", "'sanitize_callback'", "=>", "[", "$", "this", ",", "'sanitizeSetting'", "]", ",", "'default'", "=>", "$", "setting", "->", "getOption", "(", "'data'", ",", "''", ")", ",", "'show_in_rest'", "=>", "$", "showInRest", ",", "'type'", "=>", "$", "setting", "->", "getOption", "(", "'data_type'", ",", "'string'", ")", "]", ")", ";", "}", "}", "}" ]
Configure page settings if any. Called by the "admin_init" hook.
[ "Configure", "page", "settings", "if", "any", ".", "Called", "by", "the", "admin_init", "hook", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Page/Page.php#L567-L613
train
themosis/framework
src/Page/Page.php
Page.prepareSetting
protected function prepareSetting(FieldTypeInterface $setting) { if (empty($setting->getTheme()) || is_array($setting->getTheme())) { // Page settings only have the "themosis" theme available. $setting->setTheme('themosis.pages'); } $setting->setPrefix($this->getPrefix()); $setting->setOptions([ 'label' => $setting->getOption('label', ucfirst($setting->getBaseName())), 'placeholder' => $setting->getOption('placeholder', $setting->getBaseName()) ]); $attributes = array_merge([ 'class' => 'regular-text' ], $setting->getAttributes()); $setting->setAttributes($attributes); return $setting; }
php
protected function prepareSetting(FieldTypeInterface $setting) { if (empty($setting->getTheme()) || is_array($setting->getTheme())) { // Page settings only have the "themosis" theme available. $setting->setTheme('themosis.pages'); } $setting->setPrefix($this->getPrefix()); $setting->setOptions([ 'label' => $setting->getOption('label', ucfirst($setting->getBaseName())), 'placeholder' => $setting->getOption('placeholder', $setting->getBaseName()) ]); $attributes = array_merge([ 'class' => 'regular-text' ], $setting->getAttributes()); $setting->setAttributes($attributes); return $setting; }
[ "protected", "function", "prepareSetting", "(", "FieldTypeInterface", "$", "setting", ")", "{", "if", "(", "empty", "(", "$", "setting", "->", "getTheme", "(", ")", ")", "||", "is_array", "(", "$", "setting", "->", "getTheme", "(", ")", ")", ")", "{", "// Page settings only have the \"themosis\" theme available.", "$", "setting", "->", "setTheme", "(", "'themosis.pages'", ")", ";", "}", "$", "setting", "->", "setPrefix", "(", "$", "this", "->", "getPrefix", "(", ")", ")", ";", "$", "setting", "->", "setOptions", "(", "[", "'label'", "=>", "$", "setting", "->", "getOption", "(", "'label'", ",", "ucfirst", "(", "$", "setting", "->", "getBaseName", "(", ")", ")", ")", ",", "'placeholder'", "=>", "$", "setting", "->", "getOption", "(", "'placeholder'", ",", "$", "setting", "->", "getBaseName", "(", ")", ")", "]", ")", ";", "$", "attributes", "=", "array_merge", "(", "[", "'class'", "=>", "'regular-text'", "]", ",", "$", "setting", "->", "getAttributes", "(", ")", ")", ";", "$", "setting", "->", "setAttributes", "(", "$", "attributes", ")", ";", "return", "$", "setting", ";", "}" ]
Prepare the setting. @param FieldTypeInterface $setting @return FieldTypeInterface
[ "Prepare", "the", "setting", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Page/Page.php#L622-L641
train
themosis/framework
src/Page/Page.php
Page.sanitizeSetting
public function sanitizeSetting($value) { $keys = $this->repository()->getSettings()->collapse()->map(function ($setting) { /** @var FieldTypeInterface $setting */ return $setting->getName(); }); $settingName = $keys->slice($this->offset, 1)->first(); $lastSetting = $this->repository()->getSettings()->collapse()->last(); $data = collect($_POST); if ($this->offset > $keys->count() - 1) { if (empty($value)) { return ''; } // Sanitize is called one more time with a valid value. // Let's get the $settingName based on the given value // as we can't rely anymore on the offset. $settingName = $data->search($value, true); if (! $settingName) { return ''; } // Let's add a "fake" error to avoid duplicate success messages. $this->errors++; } $setting = $this->repository()->getSettingByName($settingName); $validator = $this->validator->make( $data->all(), [$setting->getName() => $setting->getOption('rules')], $this->getSettingMessages($setting), $this->getSettingPlaceholder($setting) ); // Update setting offset. $this->offset++; /** @var Validator $validator */ if ($validator->fails()) { $this->errors++; add_settings_error( $this->getSlug(), $setting->getName(), $validator->getMessageBag()->first($setting->getName()), 'error' ); return ''; } if ($settingName === $lastSetting->getName() && ! $this->errors) { add_settings_error( $this->getSlug(), 'settings_updated', __('Settings saved.'), 'updated' ); } return $value; }
php
public function sanitizeSetting($value) { $keys = $this->repository()->getSettings()->collapse()->map(function ($setting) { /** @var FieldTypeInterface $setting */ return $setting->getName(); }); $settingName = $keys->slice($this->offset, 1)->first(); $lastSetting = $this->repository()->getSettings()->collapse()->last(); $data = collect($_POST); if ($this->offset > $keys->count() - 1) { if (empty($value)) { return ''; } // Sanitize is called one more time with a valid value. // Let's get the $settingName based on the given value // as we can't rely anymore on the offset. $settingName = $data->search($value, true); if (! $settingName) { return ''; } // Let's add a "fake" error to avoid duplicate success messages. $this->errors++; } $setting = $this->repository()->getSettingByName($settingName); $validator = $this->validator->make( $data->all(), [$setting->getName() => $setting->getOption('rules')], $this->getSettingMessages($setting), $this->getSettingPlaceholder($setting) ); // Update setting offset. $this->offset++; /** @var Validator $validator */ if ($validator->fails()) { $this->errors++; add_settings_error( $this->getSlug(), $setting->getName(), $validator->getMessageBag()->first($setting->getName()), 'error' ); return ''; } if ($settingName === $lastSetting->getName() && ! $this->errors) { add_settings_error( $this->getSlug(), 'settings_updated', __('Settings saved.'), 'updated' ); } return $value; }
[ "public", "function", "sanitizeSetting", "(", "$", "value", ")", "{", "$", "keys", "=", "$", "this", "->", "repository", "(", ")", "->", "getSettings", "(", ")", "->", "collapse", "(", ")", "->", "map", "(", "function", "(", "$", "setting", ")", "{", "/** @var FieldTypeInterface $setting */", "return", "$", "setting", "->", "getName", "(", ")", ";", "}", ")", ";", "$", "settingName", "=", "$", "keys", "->", "slice", "(", "$", "this", "->", "offset", ",", "1", ")", "->", "first", "(", ")", ";", "$", "lastSetting", "=", "$", "this", "->", "repository", "(", ")", "->", "getSettings", "(", ")", "->", "collapse", "(", ")", "->", "last", "(", ")", ";", "$", "data", "=", "collect", "(", "$", "_POST", ")", ";", "if", "(", "$", "this", "->", "offset", ">", "$", "keys", "->", "count", "(", ")", "-", "1", ")", "{", "if", "(", "empty", "(", "$", "value", ")", ")", "{", "return", "''", ";", "}", "// Sanitize is called one more time with a valid value.", "// Let's get the $settingName based on the given value", "// as we can't rely anymore on the offset.", "$", "settingName", "=", "$", "data", "->", "search", "(", "$", "value", ",", "true", ")", ";", "if", "(", "!", "$", "settingName", ")", "{", "return", "''", ";", "}", "// Let's add a \"fake\" error to avoid duplicate success messages.", "$", "this", "->", "errors", "++", ";", "}", "$", "setting", "=", "$", "this", "->", "repository", "(", ")", "->", "getSettingByName", "(", "$", "settingName", ")", ";", "$", "validator", "=", "$", "this", "->", "validator", "->", "make", "(", "$", "data", "->", "all", "(", ")", ",", "[", "$", "setting", "->", "getName", "(", ")", "=>", "$", "setting", "->", "getOption", "(", "'rules'", ")", "]", ",", "$", "this", "->", "getSettingMessages", "(", "$", "setting", ")", ",", "$", "this", "->", "getSettingPlaceholder", "(", "$", "setting", ")", ")", ";", "// Update setting offset.", "$", "this", "->", "offset", "++", ";", "/** @var Validator $validator */", "if", "(", "$", "validator", "->", "fails", "(", ")", ")", "{", "$", "this", "->", "errors", "++", ";", "add_settings_error", "(", "$", "this", "->", "getSlug", "(", ")", ",", "$", "setting", "->", "getName", "(", ")", ",", "$", "validator", "->", "getMessageBag", "(", ")", "->", "first", "(", "$", "setting", "->", "getName", "(", ")", ")", ",", "'error'", ")", ";", "return", "''", ";", "}", "if", "(", "$", "settingName", "===", "$", "lastSetting", "->", "getName", "(", ")", "&&", "!", "$", "this", "->", "errors", ")", "{", "add_settings_error", "(", "$", "this", "->", "getSlug", "(", ")", ",", "'settings_updated'", ",", "__", "(", "'Settings saved.'", ")", ",", "'updated'", ")", ";", "}", "return", "$", "value", ";", "}" ]
Sanitize the setting before save. @param string|array $value @return string|array
[ "Sanitize", "the", "setting", "before", "save", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Page/Page.php#L650-L715
train
themosis/framework
src/Page/Page.php
Page.getSettingMessages
protected function getSettingMessages(FieldTypeInterface $setting): array { $messages = []; foreach ($setting->getOption('messages', []) as $attr => $message) { $messages[$setting->getName().'.'.$attr] = $message; } return $messages; }
php
protected function getSettingMessages(FieldTypeInterface $setting): array { $messages = []; foreach ($setting->getOption('messages', []) as $attr => $message) { $messages[$setting->getName().'.'.$attr] = $message; } return $messages; }
[ "protected", "function", "getSettingMessages", "(", "FieldTypeInterface", "$", "setting", ")", ":", "array", "{", "$", "messages", "=", "[", "]", ";", "foreach", "(", "$", "setting", "->", "getOption", "(", "'messages'", ",", "[", "]", ")", "as", "$", "attr", "=>", "$", "message", ")", "{", "$", "messages", "[", "$", "setting", "->", "getName", "(", ")", ".", "'.'", ".", "$", "attr", "]", "=", "$", "message", ";", "}", "return", "$", "messages", ";", "}" ]
Return the setting custom error messages. @param FieldTypeInterface $setting @return array
[ "Return", "the", "setting", "custom", "error", "messages", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Page/Page.php#L724-L733
train
themosis/framework
src/Page/Page.php
Page.getSettingPlaceholder
protected function getSettingPlaceholder(FieldTypeInterface $setting): array { $placeholder = $setting->getOption('placeholder'); if (is_null($placeholder)) { return []; } return [$setting->getName() => $placeholder]; }
php
protected function getSettingPlaceholder(FieldTypeInterface $setting): array { $placeholder = $setting->getOption('placeholder'); if (is_null($placeholder)) { return []; } return [$setting->getName() => $placeholder]; }
[ "protected", "function", "getSettingPlaceholder", "(", "FieldTypeInterface", "$", "setting", ")", ":", "array", "{", "$", "placeholder", "=", "$", "setting", "->", "getOption", "(", "'placeholder'", ")", ";", "if", "(", "is_null", "(", "$", "placeholder", ")", ")", "{", "return", "[", "]", ";", "}", "return", "[", "$", "setting", "->", "getName", "(", ")", "=>", "$", "placeholder", "]", ";", "}" ]
Return the setting placeholder. @param FieldTypeInterface $setting @return array
[ "Return", "the", "setting", "placeholder", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Page/Page.php#L742-L751
train
themosis/framework
src/Page/Page.php
Page.renderSections
public function renderSections(array $args) { $section = $this->repository()->getSectionByName($args['id']); $view = sprintf( '%s.%s.%s', $this->ui()->getTheme(), $this->ui()->getLayout(), $section->getView() ); echo $this->ui()->factory()->make($view)->with($section->getViewData())->render(); }
php
public function renderSections(array $args) { $section = $this->repository()->getSectionByName($args['id']); $view = sprintf( '%s.%s.%s', $this->ui()->getTheme(), $this->ui()->getLayout(), $section->getView() ); echo $this->ui()->factory()->make($view)->with($section->getViewData())->render(); }
[ "public", "function", "renderSections", "(", "array", "$", "args", ")", "{", "$", "section", "=", "$", "this", "->", "repository", "(", ")", "->", "getSectionByName", "(", "$", "args", "[", "'id'", "]", ")", ";", "$", "view", "=", "sprintf", "(", "'%s.%s.%s'", ",", "$", "this", "->", "ui", "(", ")", "->", "getTheme", "(", ")", ",", "$", "this", "->", "ui", "(", ")", "->", "getLayout", "(", ")", ",", "$", "section", "->", "getView", "(", ")", ")", ";", "echo", "$", "this", "->", "ui", "(", ")", "->", "factory", "(", ")", "->", "make", "(", "$", "view", ")", "->", "with", "(", "$", "section", "->", "getViewData", "(", ")", ")", "->", "render", "(", ")", ";", "}" ]
Output the section HTML. @param array $args
[ "Output", "the", "section", "HTML", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Page/Page.php#L758-L769
train
themosis/framework
src/Page/Page.php
Page.renderSettings
public function renderSettings($setting) { // Set the setting value if any. $value = get_option($setting->getName(), null); if (! is_null($value)) { $setting->setValue($value); } $view = sprintf('%s.%s', $this->ui()->getTheme(), $setting->getView(false)); echo $this->ui()->factory()->make($view)->with([ '__field' => $setting, '__page' => $this ])->render(); }
php
public function renderSettings($setting) { // Set the setting value if any. $value = get_option($setting->getName(), null); if (! is_null($value)) { $setting->setValue($value); } $view = sprintf('%s.%s', $this->ui()->getTheme(), $setting->getView(false)); echo $this->ui()->factory()->make($view)->with([ '__field' => $setting, '__page' => $this ])->render(); }
[ "public", "function", "renderSettings", "(", "$", "setting", ")", "{", "// Set the setting value if any.", "$", "value", "=", "get_option", "(", "$", "setting", "->", "getName", "(", ")", ",", "null", ")", ";", "if", "(", "!", "is_null", "(", "$", "value", ")", ")", "{", "$", "setting", "->", "setValue", "(", "$", "value", ")", ";", "}", "$", "view", "=", "sprintf", "(", "'%s.%s'", ",", "$", "this", "->", "ui", "(", ")", "->", "getTheme", "(", ")", ",", "$", "setting", "->", "getView", "(", "false", ")", ")", ";", "echo", "$", "this", "->", "ui", "(", ")", "->", "factory", "(", ")", "->", "make", "(", "$", "view", ")", "->", "with", "(", "[", "'__field'", "=>", "$", "setting", ",", "'__page'", "=>", "$", "this", "]", ")", "->", "render", "(", ")", ";", "}" ]
Output the setting HTML. @param FieldTypeInterface $setting
[ "Output", "the", "setting", "HTML", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Page/Page.php#L776-L791
train
themosis/framework
src/Page/Page.php
Page.getSettingError
public function getSettingError(string $name): array { $errors = get_settings_errors($this->getSlug()); if (empty($errors)) { return []; } return collect($errors)->first(function ($error) use ($name) { return $error['code'] === $name; }); }
php
public function getSettingError(string $name): array { $errors = get_settings_errors($this->getSlug()); if (empty($errors)) { return []; } return collect($errors)->first(function ($error) use ($name) { return $error['code'] === $name; }); }
[ "public", "function", "getSettingError", "(", "string", "$", "name", ")", ":", "array", "{", "$", "errors", "=", "get_settings_errors", "(", "$", "this", "->", "getSlug", "(", ")", ")", ";", "if", "(", "empty", "(", "$", "errors", ")", ")", "{", "return", "[", "]", ";", "}", "return", "collect", "(", "$", "errors", ")", "->", "first", "(", "function", "(", "$", "error", ")", "use", "(", "$", "name", ")", "{", "return", "$", "error", "[", "'code'", "]", "===", "$", "name", ";", "}", ")", ";", "}" ]
Return the setting error from its name. @param string $name @return array
[ "Return", "the", "setting", "error", "from", "its", "name", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Page/Page.php#L800-L811
train
themosis/framework
src/Page/Page.php
Page.setView
public function setView(string $name, bool $useShortPath = false): PageInterface { $this->ui()->useShortPath($useShortPath)->setView($name); return $this; }
php
public function setView(string $name, bool $useShortPath = false): PageInterface { $this->ui()->useShortPath($useShortPath)->setView($name); return $this; }
[ "public", "function", "setView", "(", "string", "$", "name", ",", "bool", "$", "useShortPath", "=", "false", ")", ":", "PageInterface", "{", "$", "this", "->", "ui", "(", ")", "->", "useShortPath", "(", "$", "useShortPath", ")", "->", "setView", "(", "$", "name", ")", ";", "return", "$", "this", ";", "}" ]
Set the page view path. @param string $name @param bool $useShortPath @return PageInterface
[ "Set", "the", "page", "view", "path", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Page/Page.php#L821-L826
train
themosis/framework
src/Page/Page.php
Page.parseGetRoute
public function parseGetRoute() { $request = $this->getRequest(); if (is_null($request) || ! isset($this->routes['get'])) { return; } $action = $request->get('action', '/'); if (in_array($action, array_keys($this->routes['get']))) { $callback = $this->routes['get'][$action]; $response = $this->handleCallback($callback); if (! is_a($response, Renderable::class)) { throw new \Exception('The controller method must return a view instance.'); } // Set the page view. $this->ui()->setViewInstance($response); } }
php
public function parseGetRoute() { $request = $this->getRequest(); if (is_null($request) || ! isset($this->routes['get'])) { return; } $action = $request->get('action', '/'); if (in_array($action, array_keys($this->routes['get']))) { $callback = $this->routes['get'][$action]; $response = $this->handleCallback($callback); if (! is_a($response, Renderable::class)) { throw new \Exception('The controller method must return a view instance.'); } // Set the page view. $this->ui()->setViewInstance($response); } }
[ "public", "function", "parseGetRoute", "(", ")", "{", "$", "request", "=", "$", "this", "->", "getRequest", "(", ")", ";", "if", "(", "is_null", "(", "$", "request", ")", "||", "!", "isset", "(", "$", "this", "->", "routes", "[", "'get'", "]", ")", ")", "{", "return", ";", "}", "$", "action", "=", "$", "request", "->", "get", "(", "'action'", ",", "'/'", ")", ";", "if", "(", "in_array", "(", "$", "action", ",", "array_keys", "(", "$", "this", "->", "routes", "[", "'get'", "]", ")", ")", ")", "{", "$", "callback", "=", "$", "this", "->", "routes", "[", "'get'", "]", "[", "$", "action", "]", ";", "$", "response", "=", "$", "this", "->", "handleCallback", "(", "$", "callback", ")", ";", "if", "(", "!", "is_a", "(", "$", "response", ",", "Renderable", "::", "class", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'The controller method must return a view instance.'", ")", ";", "}", "// Set the page view.", "$", "this", "->", "ui", "(", ")", "->", "setViewInstance", "(", "$", "response", ")", ";", "}", "}" ]
Parse page GET requests.
[ "Parse", "page", "GET", "requests", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Page/Page.php#L841-L862
train
themosis/framework
src/Page/Page.php
Page.parsePostRoute
public function parsePostRoute() { if (empty($this->routes) || ! isset($this->routes['post'])) { return; } foreach ($this->routes['post'] as $action => $callback) { $this->action->add('admin_post_'.$action, $callback); } }
php
public function parsePostRoute() { if (empty($this->routes) || ! isset($this->routes['post'])) { return; } foreach ($this->routes['post'] as $action => $callback) { $this->action->add('admin_post_'.$action, $callback); } }
[ "public", "function", "parsePostRoute", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "routes", ")", "||", "!", "isset", "(", "$", "this", "->", "routes", "[", "'post'", "]", ")", ")", "{", "return", ";", "}", "foreach", "(", "$", "this", "->", "routes", "[", "'post'", "]", "as", "$", "action", "=>", "$", "callback", ")", "{", "$", "this", "->", "action", "->", "add", "(", "'admin_post_'", ".", "$", "action", ",", "$", "callback", ")", ";", "}", "}" ]
Parse page POST requests. Note: POST requests should always target "admin-post.php" on a custom page form.
[ "Parse", "page", "POST", "requests", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Page/Page.php#L870-L879
train
themosis/framework
src/Page/Page.php
Page.route
public function route(string $action, $callback, string $method = 'get', string $title = ''): PageInterface { $method = strtolower($method); $action = $this->parseAction($action, $method); $this->routes[$method][$action] = $callback; $this->titles[$action] = ! empty($title) ? $title : $this->getTitle(); $this->registerRouteActions(); return $this; }
php
public function route(string $action, $callback, string $method = 'get', string $title = ''): PageInterface { $method = strtolower($method); $action = $this->parseAction($action, $method); $this->routes[$method][$action] = $callback; $this->titles[$action] = ! empty($title) ? $title : $this->getTitle(); $this->registerRouteActions(); return $this; }
[ "public", "function", "route", "(", "string", "$", "action", ",", "$", "callback", ",", "string", "$", "method", "=", "'get'", ",", "string", "$", "title", "=", "''", ")", ":", "PageInterface", "{", "$", "method", "=", "strtolower", "(", "$", "method", ")", ";", "$", "action", "=", "$", "this", "->", "parseAction", "(", "$", "action", ",", "$", "method", ")", ";", "$", "this", "->", "routes", "[", "$", "method", "]", "[", "$", "action", "]", "=", "$", "callback", ";", "$", "this", "->", "titles", "[", "$", "action", "]", "=", "!", "empty", "(", "$", "title", ")", "?", "$", "title", ":", "$", "this", "->", "getTitle", "(", ")", ";", "$", "this", "->", "registerRouteActions", "(", ")", ";", "return", "$", "this", ";", "}" ]
Register page routes. @param string $action @param callable|string $callback @param string $method @param string $title @return PageInterface
[ "Register", "page", "routes", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Page/Page.php#L891-L903
train
themosis/framework
src/Page/Page.php
Page.registerRouteActions
protected function registerRouteActions() { // Actions for page routing. $this->action->add('load-toplevel_page_'.$this->getSlug(), [$this, 'parseGetRoute']); $this->action->add('load-admin_page_'.$this->getSlug(), [$this, 'parseGetRoute']); $this->action->add('load-'.$this->findParentHook().'_page_'.$this->getSlug(), [$this, 'parseGetRoute']); $this->action->add('admin_init', [$this, 'parsePostRoute']); $this->filter->add('admin_title', [$this, 'handleTitle']); }
php
protected function registerRouteActions() { // Actions for page routing. $this->action->add('load-toplevel_page_'.$this->getSlug(), [$this, 'parseGetRoute']); $this->action->add('load-admin_page_'.$this->getSlug(), [$this, 'parseGetRoute']); $this->action->add('load-'.$this->findParentHook().'_page_'.$this->getSlug(), [$this, 'parseGetRoute']); $this->action->add('admin_init', [$this, 'parsePostRoute']); $this->filter->add('admin_title', [$this, 'handleTitle']); }
[ "protected", "function", "registerRouteActions", "(", ")", "{", "// Actions for page routing.", "$", "this", "->", "action", "->", "add", "(", "'load-toplevel_page_'", ".", "$", "this", "->", "getSlug", "(", ")", ",", "[", "$", "this", ",", "'parseGetRoute'", "]", ")", ";", "$", "this", "->", "action", "->", "add", "(", "'load-admin_page_'", ".", "$", "this", "->", "getSlug", "(", ")", ",", "[", "$", "this", ",", "'parseGetRoute'", "]", ")", ";", "$", "this", "->", "action", "->", "add", "(", "'load-'", ".", "$", "this", "->", "findParentHook", "(", ")", ".", "'_page_'", ".", "$", "this", "->", "getSlug", "(", ")", ",", "[", "$", "this", ",", "'parseGetRoute'", "]", ")", ";", "$", "this", "->", "action", "->", "add", "(", "'admin_init'", ",", "[", "$", "this", ",", "'parsePostRoute'", "]", ")", ";", "$", "this", "->", "filter", "->", "add", "(", "'admin_title'", ",", "[", "$", "this", ",", "'handleTitle'", "]", ")", ";", "}" ]
Register page routes actions and filters.
[ "Register", "page", "routes", "actions", "and", "filters", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Page/Page.php#L908-L917
train
themosis/framework
src/Page/Page.php
Page.parseAction
protected function parseAction(string $action, string $method): string { if ('post' === $method) { return $this->getSlug().'_'.$action; } return $action; }
php
protected function parseAction(string $action, string $method): string { if ('post' === $method) { return $this->getSlug().'_'.$action; } return $action; }
[ "protected", "function", "parseAction", "(", "string", "$", "action", ",", "string", "$", "method", ")", ":", "string", "{", "if", "(", "'post'", "===", "$", "method", ")", "{", "return", "$", "this", "->", "getSlug", "(", ")", ".", "'_'", ".", "$", "action", ";", "}", "return", "$", "action", ";", "}" ]
Format the action name. @param string $action @param string $method @return string
[ "Format", "the", "action", "name", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Page/Page.php#L927-L934
train
themosis/framework
src/Page/Page.php
Page.handleTitle
public function handleTitle($title) { if (is_null($request = $this->getRequest()) || empty($this->titles)) { return $title; } if (in_array($action = $request->get('action'), array_keys($this->titles))) { return $this->titles[$action]; } return $title; }
php
public function handleTitle($title) { if (is_null($request = $this->getRequest()) || empty($this->titles)) { return $title; } if (in_array($action = $request->get('action'), array_keys($this->titles))) { return $this->titles[$action]; } return $title; }
[ "public", "function", "handleTitle", "(", "$", "title", ")", "{", "if", "(", "is_null", "(", "$", "request", "=", "$", "this", "->", "getRequest", "(", ")", ")", "||", "empty", "(", "$", "this", "->", "titles", ")", ")", "{", "return", "$", "title", ";", "}", "if", "(", "in_array", "(", "$", "action", "=", "$", "request", "->", "get", "(", "'action'", ")", ",", "array_keys", "(", "$", "this", "->", "titles", ")", ")", ")", "{", "return", "$", "this", "->", "titles", "[", "$", "action", "]", ";", "}", "return", "$", "title", ";", "}" ]
Called by the "admin_title" filter. Handle the page titles. @param string $title @return string
[ "Called", "by", "the", "admin_title", "filter", ".", "Handle", "the", "page", "titles", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Page/Page.php#L943-L954
train
themosis/framework
src/Page/Page.php
Page.getContainer
public function getContainer(): Container { if (is_null($this->container)) { $this->container = $this->ui()->factory()->getContainer(); } return $this->container; }
php
public function getContainer(): Container { if (is_null($this->container)) { $this->container = $this->ui()->factory()->getContainer(); } return $this->container; }
[ "public", "function", "getContainer", "(", ")", ":", "Container", "{", "if", "(", "is_null", "(", "$", "this", "->", "container", ")", ")", "{", "$", "this", "->", "container", "=", "$", "this", "->", "ui", "(", ")", "->", "factory", "(", ")", "->", "getContainer", "(", ")", ";", "}", "return", "$", "this", "->", "container", ";", "}" ]
Return the service container instance. @return Container
[ "Return", "the", "service", "container", "instance", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Page/Page.php#L961-L968
train
themosis/framework
src/Html/HtmlBuilder.php
HtmlBuilder.setCharset
public function setCharset($charset = null) { if (! is_null($charset)) { $this->charset = $charset; } elseif (defined('THEMOSIS_CHARSET')) { $this->charset = THEMOSIS_CHARSET; } elseif (function_exists('get_bloginfo')) { $this->charset = get_bloginfo('charset'); } return $this; }
php
public function setCharset($charset = null) { if (! is_null($charset)) { $this->charset = $charset; } elseif (defined('THEMOSIS_CHARSET')) { $this->charset = THEMOSIS_CHARSET; } elseif (function_exists('get_bloginfo')) { $this->charset = get_bloginfo('charset'); } return $this; }
[ "public", "function", "setCharset", "(", "$", "charset", "=", "null", ")", "{", "if", "(", "!", "is_null", "(", "$", "charset", ")", ")", "{", "$", "this", "->", "charset", "=", "$", "charset", ";", "}", "elseif", "(", "defined", "(", "'THEMOSIS_CHARSET'", ")", ")", "{", "$", "this", "->", "charset", "=", "THEMOSIS_CHARSET", ";", "}", "elseif", "(", "function_exists", "(", "'get_bloginfo'", ")", ")", "{", "$", "this", "->", "charset", "=", "get_bloginfo", "(", "'charset'", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set the encoding charset. Defaults to UTF8. @param string $charset @return \Themosis\Html\HtmlBuilder
[ "Set", "the", "encoding", "charset", ".", "Defaults", "to", "UTF8", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Html/HtmlBuilder.php#L25-L36
train
themosis/framework
src/Html/HtmlBuilder.php
HtmlBuilder.attributeElement
protected function attributeElement($key, $value) { // For numeric keys we will assume that the value is a boolean attribute // where the presence of the attribute represents a true value and the // absence represents a false value. // This will convert HTML attributes such as "required" to a correct // form instead of using incorrect numeric. if (is_numeric($key)) { return $value; } // Treat boolean attributes as HTML properties if (is_bool($value) && $key !== 'value') { return $value ? $key : ''; } if (! is_null($value)) { return $key.'="'.$this->special($value).'"'; } return null; }
php
protected function attributeElement($key, $value) { // For numeric keys we will assume that the value is a boolean attribute // where the presence of the attribute represents a true value and the // absence represents a false value. // This will convert HTML attributes such as "required" to a correct // form instead of using incorrect numeric. if (is_numeric($key)) { return $value; } // Treat boolean attributes as HTML properties if (is_bool($value) && $key !== 'value') { return $value ? $key : ''; } if (! is_null($value)) { return $key.'="'.$this->special($value).'"'; } return null; }
[ "protected", "function", "attributeElement", "(", "$", "key", ",", "$", "value", ")", "{", "// For numeric keys we will assume that the value is a boolean attribute", "// where the presence of the attribute represents a true value and the", "// absence represents a false value.", "// This will convert HTML attributes such as \"required\" to a correct", "// form instead of using incorrect numeric.", "if", "(", "is_numeric", "(", "$", "key", ")", ")", "{", "return", "$", "value", ";", "}", "// Treat boolean attributes as HTML properties", "if", "(", "is_bool", "(", "$", "value", ")", "&&", "$", "key", "!==", "'value'", ")", "{", "return", "$", "value", "?", "$", "key", ":", "''", ";", "}", "if", "(", "!", "is_null", "(", "$", "value", ")", ")", "{", "return", "$", "key", ".", "'=\"'", ".", "$", "this", "->", "special", "(", "$", "value", ")", ".", "'\"'", ";", "}", "return", "null", ";", "}" ]
Build the attribute. @param string $key @param string $value @return string|null
[ "Build", "the", "attribute", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Html/HtmlBuilder.php#L68-L87
train
themosis/framework
src/View/Loop.php
Loop.thumbnailUrl
public function thumbnailUrl($size = null, $icon = false) { $data = wp_get_attachment_image_src(get_post_thumbnail_id($this->id()), $size, $icon); return (empty($data)) ? null : $data[0]; }
php
public function thumbnailUrl($size = null, $icon = false) { $data = wp_get_attachment_image_src(get_post_thumbnail_id($this->id()), $size, $icon); return (empty($data)) ? null : $data[0]; }
[ "public", "function", "thumbnailUrl", "(", "$", "size", "=", "null", ",", "$", "icon", "=", "false", ")", "{", "$", "data", "=", "wp_get_attachment_image_src", "(", "get_post_thumbnail_id", "(", "$", "this", "->", "id", "(", ")", ")", ",", "$", "size", ",", "$", "icon", ")", ";", "return", "(", "empty", "(", "$", "data", ")", ")", "?", "null", ":", "$", "data", "[", "0", "]", ";", "}" ]
Get thumbnail url of current post. @param string|array $size The size of the current post thumbnail. @param bool $icon @return null|string
[ "Get", "thumbnail", "url", "of", "current", "post", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/View/Loop.php#L106-L111
train
themosis/framework
src/Route/Route.php
Route.setConditions
public function setConditions(array $conditions = []) { $this->conditions = $conditions; $this->condition = $this->parseCondition($this->uri()); $this->conditionParams = $this->parseConditionParams($this->getAction()); return $this; }
php
public function setConditions(array $conditions = []) { $this->conditions = $conditions; $this->condition = $this->parseCondition($this->uri()); $this->conditionParams = $this->parseConditionParams($this->getAction()); return $this; }
[ "public", "function", "setConditions", "(", "array", "$", "conditions", "=", "[", "]", ")", "{", "$", "this", "->", "conditions", "=", "$", "conditions", ";", "$", "this", "->", "condition", "=", "$", "this", "->", "parseCondition", "(", "$", "this", "->", "uri", "(", ")", ")", ";", "$", "this", "->", "conditionParams", "=", "$", "this", "->", "parseConditionParams", "(", "$", "this", "->", "getAction", "(", ")", ")", ";", "return", "$", "this", ";", "}" ]
Set route WordPress conditions rules. @param array $conditions @return \Themosis\Route\Route
[ "Set", "route", "WordPress", "conditions", "rules", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Route/Route.php#L100-L108
train
themosis/framework
src/Route/Route.php
Route.parseCondition
protected function parseCondition(string $condition): string { $conditions = $this->getConditions(); foreach ($conditions as $signature => $conds) { $conds = is_array($conds) ? $conds : [$conds]; if (in_array($condition, $conds, true)) { return $signature; } } return ''; }
php
protected function parseCondition(string $condition): string { $conditions = $this->getConditions(); foreach ($conditions as $signature => $conds) { $conds = is_array($conds) ? $conds : [$conds]; if (in_array($condition, $conds, true)) { return $signature; } } return ''; }
[ "protected", "function", "parseCondition", "(", "string", "$", "condition", ")", ":", "string", "{", "$", "conditions", "=", "$", "this", "->", "getConditions", "(", ")", ";", "foreach", "(", "$", "conditions", "as", "$", "signature", "=>", "$", "conds", ")", "{", "$", "conds", "=", "is_array", "(", "$", "conds", ")", "?", "$", "conds", ":", "[", "$", "conds", "]", ";", "if", "(", "in_array", "(", "$", "condition", ",", "$", "conds", ",", "true", ")", ")", "{", "return", "$", "signature", ";", "}", "}", "return", "''", ";", "}" ]
Parse the route condition based on global list of conditions. Return the WordPress conditional function. @param string $condition @return string
[ "Parse", "the", "route", "condition", "based", "on", "global", "list", "of", "conditions", ".", "Return", "the", "WordPress", "conditional", "function", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Route/Route.php#L118-L131
train
themosis/framework
src/Route/Route.php
Route.parseConditionParams
protected function parseConditionParams(array $action): array { if (empty($this->condition)) { return []; } $params = Arr::first($action, function ($value, $key) { return is_numeric($key); }); return [$params]; }
php
protected function parseConditionParams(array $action): array { if (empty($this->condition)) { return []; } $params = Arr::first($action, function ($value, $key) { return is_numeric($key); }); return [$params]; }
[ "protected", "function", "parseConditionParams", "(", "array", "$", "action", ")", ":", "array", "{", "if", "(", "empty", "(", "$", "this", "->", "condition", ")", ")", "{", "return", "[", "]", ";", "}", "$", "params", "=", "Arr", "::", "first", "(", "$", "action", ",", "function", "(", "$", "value", ",", "$", "key", ")", "{", "return", "is_numeric", "(", "$", "key", ")", ";", "}", ")", ";", "return", "[", "$", "params", "]", ";", "}" ]
Parse route action and get any WordPress conditional parameters if any defined. @param array $action @return array
[ "Parse", "route", "action", "and", "get", "any", "WordPress", "conditional", "parameters", "if", "any", "defined", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Route/Route.php#L141-L152
train
themosis/framework
src/Page/PageSettingsRepository.php
PageSettingsRepository.setSettings
public function setSettings(array $settings): SettingsRepositoryInterface { $this->parseCompatibleSettings($settings); $this->settings = $settings; return $this; }
php
public function setSettings(array $settings): SettingsRepositoryInterface { $this->parseCompatibleSettings($settings); $this->settings = $settings; return $this; }
[ "public", "function", "setSettings", "(", "array", "$", "settings", ")", ":", "SettingsRepositoryInterface", "{", "$", "this", "->", "parseCompatibleSettings", "(", "$", "settings", ")", ";", "$", "this", "->", "settings", "=", "$", "settings", ";", "return", "$", "this", ";", "}" ]
Set the page repository settings. @param array $settings @return SettingsRepositoryInterface
[ "Set", "the", "page", "repository", "settings", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Page/PageSettingsRepository.php#L54-L60
train
themosis/framework
src/Page/PageSettingsRepository.php
PageSettingsRepository.getSettingByName
public function getSettingByName(string $name): FieldTypeInterface { return $this->getSettings()->collapse()->first(function ($setting) use ($name) { /** @var FieldTypeInterface $setting */ return $name === $setting->getName(); }); }
php
public function getSettingByName(string $name): FieldTypeInterface { return $this->getSettings()->collapse()->first(function ($setting) use ($name) { /** @var FieldTypeInterface $setting */ return $name === $setting->getName(); }); }
[ "public", "function", "getSettingByName", "(", "string", "$", "name", ")", ":", "FieldTypeInterface", "{", "return", "$", "this", "->", "getSettings", "(", ")", "->", "collapse", "(", ")", "->", "first", "(", "function", "(", "$", "setting", ")", "use", "(", "$", "name", ")", "{", "/** @var FieldTypeInterface $setting */", "return", "$", "name", "===", "$", "setting", "->", "getName", "(", ")", ";", "}", ")", ";", "}" ]
Return the setting instance based on its name. @param string $name @return FieldTypeInterface
[ "Return", "the", "setting", "instance", "based", "on", "its", "name", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Page/PageSettingsRepository.php#L79-L85
train
themosis/framework
src/Page/PageSettingsRepository.php
PageSettingsRepository.getSectionByName
public function getSectionByName(string $name): SectionInterface { return $this->getSections()->first(function ($section) use ($name) { /** @var SectionInterface $section */ return $name === $section->getId(); }); }
php
public function getSectionByName(string $name): SectionInterface { return $this->getSections()->first(function ($section) use ($name) { /** @var SectionInterface $section */ return $name === $section->getId(); }); }
[ "public", "function", "getSectionByName", "(", "string", "$", "name", ")", ":", "SectionInterface", "{", "return", "$", "this", "->", "getSections", "(", ")", "->", "first", "(", "function", "(", "$", "section", ")", "use", "(", "$", "name", ")", "{", "/** @var SectionInterface $section */", "return", "$", "name", "===", "$", "section", "->", "getId", "(", ")", ";", "}", ")", ";", "}" ]
Return the section instance based on its name. @param string $name @return SectionInterface
[ "Return", "the", "section", "instance", "based", "on", "its", "name", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Page/PageSettingsRepository.php#L94-L100
train
themosis/framework
src/Page/PageSettingsRepository.php
PageSettingsRepository.parseCompatibleSettings
protected function parseCompatibleSettings(array $settings) { $settings = collect($settings)->collapse()->all(); foreach ($settings as $setting) { if ($setting instanceof CanHandlePageSettings) { $setting->settingGet(); } } }
php
protected function parseCompatibleSettings(array $settings) { $settings = collect($settings)->collapse()->all(); foreach ($settings as $setting) { if ($setting instanceof CanHandlePageSettings) { $setting->settingGet(); } } }
[ "protected", "function", "parseCompatibleSettings", "(", "array", "$", "settings", ")", "{", "$", "settings", "=", "collect", "(", "$", "settings", ")", "->", "collapse", "(", ")", "->", "all", "(", ")", ";", "foreach", "(", "$", "settings", "as", "$", "setting", ")", "{", "if", "(", "$", "setting", "instanceof", "CanHandlePageSettings", ")", "{", "$", "setting", "->", "settingGet", "(", ")", ";", "}", "}", "}" ]
Parse page settings. Throw an exception if user is using a field not supported. @param array $settings @throws \Exception
[ "Parse", "page", "settings", ".", "Throw", "an", "exception", "if", "user", "is", "using", "a", "field", "not", "supported", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Page/PageSettingsRepository.php#L110-L119
train
themosis/framework
src/Page/PageView.php
PageView.getView
public function getView(): View { $path = $this->useShortViewPath ? $this->getViewPath() : sprintf('%s.%s.%s', $this->getTheme(), $this->getLayout(), $this->getViewPath()); if (is_null($this->viewInstance)) { $this->viewInstance = $this->factory->make($path); } return $this->viewInstance; }
php
public function getView(): View { $path = $this->useShortViewPath ? $this->getViewPath() : sprintf('%s.%s.%s', $this->getTheme(), $this->getLayout(), $this->getViewPath()); if (is_null($this->viewInstance)) { $this->viewInstance = $this->factory->make($path); } return $this->viewInstance; }
[ "public", "function", "getView", "(", ")", ":", "View", "{", "$", "path", "=", "$", "this", "->", "useShortViewPath", "?", "$", "this", "->", "getViewPath", "(", ")", ":", "sprintf", "(", "'%s.%s.%s'", ",", "$", "this", "->", "getTheme", "(", ")", ",", "$", "this", "->", "getLayout", "(", ")", ",", "$", "this", "->", "getViewPath", "(", ")", ")", ";", "if", "(", "is_null", "(", "$", "this", "->", "viewInstance", ")", ")", "{", "$", "this", "->", "viewInstance", "=", "$", "this", "->", "factory", "->", "make", "(", "$", "path", ")", ";", "}", "return", "$", "this", "->", "viewInstance", ";", "}" ]
Return the page view. @return View
[ "Return", "the", "page", "view", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Page/PageView.php#L142-L152
train
themosis/framework
src/Asset/Finder.php
Finder.addLocation
public function addLocation(string $path, string $url): Finder { $path = rtrim($path, '\/'); $url = rtrim($url, '\/'); $this->locations[$path] = $url; return $this; }
php
public function addLocation(string $path, string $url): Finder { $path = rtrim($path, '\/'); $url = rtrim($url, '\/'); $this->locations[$path] = $url; return $this; }
[ "public", "function", "addLocation", "(", "string", "$", "path", ",", "string", "$", "url", ")", ":", "Finder", "{", "$", "path", "=", "rtrim", "(", "$", "path", ",", "'\\/'", ")", ";", "$", "url", "=", "rtrim", "(", "$", "url", ",", "'\\/'", ")", ";", "$", "this", "->", "locations", "[", "$", "path", "]", "=", "$", "url", ";", "return", "$", "this", ";", "}" ]
Add a base location in order to find an asset. @param string $path @param string $url @return Finder
[ "Add", "a", "base", "location", "in", "order", "to", "find", "an", "asset", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Asset/Finder.php#L37-L45
train
themosis/framework
src/Asset/Finder.php
Finder.addLocations
public function addLocations(array $paths): Finder { foreach ($paths as $path => $url) { $this->addLocation($path, $url); } return $this; }
php
public function addLocations(array $paths): Finder { foreach ($paths as $path => $url) { $this->addLocation($path, $url); } return $this; }
[ "public", "function", "addLocations", "(", "array", "$", "paths", ")", ":", "Finder", "{", "foreach", "(", "$", "paths", "as", "$", "path", "=>", "$", "url", ")", "{", "$", "this", "->", "addLocation", "(", "$", "path", ",", "$", "url", ")", ";", "}", "return", "$", "this", ";", "}" ]
Add multiple locations. The key is the asset path and the value its URL. @param array $paths @return Finder
[ "Add", "multiple", "locations", ".", "The", "key", "is", "the", "asset", "path", "and", "the", "value", "its", "URL", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Asset/Finder.php#L55-L62
train
themosis/framework
src/Asset/Finder.php
Finder.find
public function find(string $path): AssetFileInterface { if ($this->isExternal($path)) { return (new File($this->files)) ->setPath('') ->setUrl($path) ->setExternal(true) ->setType($path); } $path = trim($path, '\/'); foreach ($this->locations as $dir => $url) { if ($this->files->exists($fullPath = $dir.'/'.$path)) { return (new File($this->files)) ->setPath($fullPath) ->setUrl($url.'/'.$path) ->setExternal(false) ->setType($fullPath); } } throw new AssetException('Unable to find the asset with the following path: '.$path); }
php
public function find(string $path): AssetFileInterface { if ($this->isExternal($path)) { return (new File($this->files)) ->setPath('') ->setUrl($path) ->setExternal(true) ->setType($path); } $path = trim($path, '\/'); foreach ($this->locations as $dir => $url) { if ($this->files->exists($fullPath = $dir.'/'.$path)) { return (new File($this->files)) ->setPath($fullPath) ->setUrl($url.'/'.$path) ->setExternal(false) ->setType($fullPath); } } throw new AssetException('Unable to find the asset with the following path: '.$path); }
[ "public", "function", "find", "(", "string", "$", "path", ")", ":", "AssetFileInterface", "{", "if", "(", "$", "this", "->", "isExternal", "(", "$", "path", ")", ")", "{", "return", "(", "new", "File", "(", "$", "this", "->", "files", ")", ")", "->", "setPath", "(", "''", ")", "->", "setUrl", "(", "$", "path", ")", "->", "setExternal", "(", "true", ")", "->", "setType", "(", "$", "path", ")", ";", "}", "$", "path", "=", "trim", "(", "$", "path", ",", "'\\/'", ")", ";", "foreach", "(", "$", "this", "->", "locations", "as", "$", "dir", "=>", "$", "url", ")", "{", "if", "(", "$", "this", "->", "files", "->", "exists", "(", "$", "fullPath", "=", "$", "dir", ".", "'/'", ".", "$", "path", ")", ")", "{", "return", "(", "new", "File", "(", "$", "this", "->", "files", ")", ")", "->", "setPath", "(", "$", "fullPath", ")", "->", "setUrl", "(", "$", "url", ".", "'/'", ".", "$", "path", ")", "->", "setExternal", "(", "false", ")", "->", "setType", "(", "$", "fullPath", ")", ";", "}", "}", "throw", "new", "AssetException", "(", "'Unable to find the asset with the following path: '", ".", "$", "path", ")", ";", "}" ]
Return an asset file instance if found. @param string $path @throws AssetException @return AssetFileInterface
[ "Return", "an", "asset", "file", "instance", "if", "found", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Asset/Finder.php#L83-L106
train
themosis/framework
src/Asset/Finder.php
Finder.isExternal
protected function isExternal(string $path): bool { foreach ($this->schemes as $scheme) { if (strpos($path, $scheme) !== false) { return true; } } return false; }
php
protected function isExternal(string $path): bool { foreach ($this->schemes as $scheme) { if (strpos($path, $scheme) !== false) { return true; } } return false; }
[ "protected", "function", "isExternal", "(", "string", "$", "path", ")", ":", "bool", "{", "foreach", "(", "$", "this", "->", "schemes", "as", "$", "scheme", ")", "{", "if", "(", "strpos", "(", "$", "path", ",", "$", "scheme", ")", "!==", "false", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Check if given path is an external asset or not. @param string $path @return bool
[ "Check", "if", "given", "path", "is", "an", "external", "asset", "or", "not", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Asset/Finder.php#L115-L124
train
themosis/framework
src/Forms/FormFactory.php
FormFactory.make
public function make($dataClass = null, $options = [], $builder = FormBuilder::class): FormBuilderInterface { $dataMapperManager = new DataMapperManager(PropertyAccess::createPropertyAccessor()); $form = new Form( $dataClass, new FieldsRepository(), $this->validation, $this->viewer, $dataMapperManager ); $form->setManager($this->manager); $form->setResourceTransformerFactory($this->factory); $form->setAttributes($this->attributes); $form->setOptions($options); $this->builder = new $builder($form, $dataMapperManager, $dataClass); return $this->builder; }
php
public function make($dataClass = null, $options = [], $builder = FormBuilder::class): FormBuilderInterface { $dataMapperManager = new DataMapperManager(PropertyAccess::createPropertyAccessor()); $form = new Form( $dataClass, new FieldsRepository(), $this->validation, $this->viewer, $dataMapperManager ); $form->setManager($this->manager); $form->setResourceTransformerFactory($this->factory); $form->setAttributes($this->attributes); $form->setOptions($options); $this->builder = new $builder($form, $dataMapperManager, $dataClass); return $this->builder; }
[ "public", "function", "make", "(", "$", "dataClass", "=", "null", ",", "$", "options", "=", "[", "]", ",", "$", "builder", "=", "FormBuilder", "::", "class", ")", ":", "FormBuilderInterface", "{", "$", "dataMapperManager", "=", "new", "DataMapperManager", "(", "PropertyAccess", "::", "createPropertyAccessor", "(", ")", ")", ";", "$", "form", "=", "new", "Form", "(", "$", "dataClass", ",", "new", "FieldsRepository", "(", ")", ",", "$", "this", "->", "validation", ",", "$", "this", "->", "viewer", ",", "$", "dataMapperManager", ")", ";", "$", "form", "->", "setManager", "(", "$", "this", "->", "manager", ")", ";", "$", "form", "->", "setResourceTransformerFactory", "(", "$", "this", "->", "factory", ")", ";", "$", "form", "->", "setAttributes", "(", "$", "this", "->", "attributes", ")", ";", "$", "form", "->", "setOptions", "(", "$", "options", ")", ";", "$", "this", "->", "builder", "=", "new", "$", "builder", "(", "$", "form", ",", "$", "dataMapperManager", ",", "$", "dataClass", ")", ";", "return", "$", "this", "->", "builder", ";", "}" ]
Create a FormBuilderInterface instance. @param mixed $dataClass Data object (DTO). @param array $options @param string $builder A FieldBuilderInterface class. @return FormBuilderInterface
[ "Create", "a", "FormBuilderInterface", "instance", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/FormFactory.php#L62-L81
train
themosis/framework
src/Support/CallbackHandler.php
CallbackHandler.handleCallback
protected function handleCallback($callback, array $args = []) { $response = null; // Check if $callback is a closure. if ($callback instanceof \Closure || is_array($callback)) { $response = call_user_func($callback, $args); } elseif (is_string($callback)) { if (false !== strpos($callback, '@') || class_exists($callback)) { // We use a "ClassName@method" syntax. // Let's get a class instance and call its method. $callbackArray = $this->handleClassCallback($callback); $response = call_user_func($callbackArray, $args); } else { // Used as a classic callback function. $response = call_user_func($callback, $args); } } return $response; }
php
protected function handleCallback($callback, array $args = []) { $response = null; // Check if $callback is a closure. if ($callback instanceof \Closure || is_array($callback)) { $response = call_user_func($callback, $args); } elseif (is_string($callback)) { if (false !== strpos($callback, '@') || class_exists($callback)) { // We use a "ClassName@method" syntax. // Let's get a class instance and call its method. $callbackArray = $this->handleClassCallback($callback); $response = call_user_func($callbackArray, $args); } else { // Used as a classic callback function. $response = call_user_func($callback, $args); } } return $response; }
[ "protected", "function", "handleCallback", "(", "$", "callback", ",", "array", "$", "args", "=", "[", "]", ")", "{", "$", "response", "=", "null", ";", "// Check if $callback is a closure.", "if", "(", "$", "callback", "instanceof", "\\", "Closure", "||", "is_array", "(", "$", "callback", ")", ")", "{", "$", "response", "=", "call_user_func", "(", "$", "callback", ",", "$", "args", ")", ";", "}", "elseif", "(", "is_string", "(", "$", "callback", ")", ")", "{", "if", "(", "false", "!==", "strpos", "(", "$", "callback", ",", "'@'", ")", "||", "class_exists", "(", "$", "callback", ")", ")", "{", "// We use a \"ClassName@method\" syntax.", "// Let's get a class instance and call its method.", "$", "callbackArray", "=", "$", "this", "->", "handleClassCallback", "(", "$", "callback", ")", ";", "$", "response", "=", "call_user_func", "(", "$", "callbackArray", ",", "$", "args", ")", ";", "}", "else", "{", "// Used as a classic callback function.", "$", "response", "=", "call_user_func", "(", "$", "callback", ",", "$", "args", ")", ";", "}", "}", "return", "$", "response", ";", "}" ]
Handle the callback to execute. @param string|array|callable $callback @param array $args @return mixed|string
[ "Handle", "the", "callback", "to", "execute", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Support/CallbackHandler.php#L36-L56
train
themosis/framework
src/Forms/Fields/Types/ColorType.php
ColorType.getDefaultColors
protected function getDefaultColors() { $colors = [ [ 'name' => 'Pale pink', 'color' => '#f78da7' ], [ 'name' => 'Vivid red', 'color' => '#cf2e2e' ], [ 'name' => 'Luminous vivid orange', 'color' => '#ff6900' ], [ 'name' => 'Luminous vivid amber', 'color' => '#fcb900' ], [ 'name' => 'Light green cyan', 'color' => '#7bdcb5' ], [ 'name' => 'Vivid green cyan', 'color' => '#00d084' ], [ 'name' => 'Pale cyan blue', 'color' => '#8ed1fc' ], [ 'name' => 'Vivid cyan blue', 'color' => '#0693e3' ], [ 'name' => 'Very light gray', 'color' => '#eeeeee' ], [ 'name' => 'Cyan bluish gray', 'color' => '#abb8c3' ], [ 'name' => 'Very dark gray', 'color' => '#313131' ] ]; return array_map(function (array $color) { return [ 'name' => function_exists('__') ? __($color['name'], Application::TEXTDOMAIN) : $color['name'], 'color' => $color['color'] ]; }, $colors); }
php
protected function getDefaultColors() { $colors = [ [ 'name' => 'Pale pink', 'color' => '#f78da7' ], [ 'name' => 'Vivid red', 'color' => '#cf2e2e' ], [ 'name' => 'Luminous vivid orange', 'color' => '#ff6900' ], [ 'name' => 'Luminous vivid amber', 'color' => '#fcb900' ], [ 'name' => 'Light green cyan', 'color' => '#7bdcb5' ], [ 'name' => 'Vivid green cyan', 'color' => '#00d084' ], [ 'name' => 'Pale cyan blue', 'color' => '#8ed1fc' ], [ 'name' => 'Vivid cyan blue', 'color' => '#0693e3' ], [ 'name' => 'Very light gray', 'color' => '#eeeeee' ], [ 'name' => 'Cyan bluish gray', 'color' => '#abb8c3' ], [ 'name' => 'Very dark gray', 'color' => '#313131' ] ]; return array_map(function (array $color) { return [ 'name' => function_exists('__') ? __($color['name'], Application::TEXTDOMAIN) : $color['name'], 'color' => $color['color'] ]; }, $colors); }
[ "protected", "function", "getDefaultColors", "(", ")", "{", "$", "colors", "=", "[", "[", "'name'", "=>", "'Pale pink'", ",", "'color'", "=>", "'#f78da7'", "]", ",", "[", "'name'", "=>", "'Vivid red'", ",", "'color'", "=>", "'#cf2e2e'", "]", ",", "[", "'name'", "=>", "'Luminous vivid orange'", ",", "'color'", "=>", "'#ff6900'", "]", ",", "[", "'name'", "=>", "'Luminous vivid amber'", ",", "'color'", "=>", "'#fcb900'", "]", ",", "[", "'name'", "=>", "'Light green cyan'", ",", "'color'", "=>", "'#7bdcb5'", "]", ",", "[", "'name'", "=>", "'Vivid green cyan'", ",", "'color'", "=>", "'#00d084'", "]", ",", "[", "'name'", "=>", "'Pale cyan blue'", ",", "'color'", "=>", "'#8ed1fc'", "]", ",", "[", "'name'", "=>", "'Vivid cyan blue'", ",", "'color'", "=>", "'#0693e3'", "]", ",", "[", "'name'", "=>", "'Very light gray'", ",", "'color'", "=>", "'#eeeeee'", "]", ",", "[", "'name'", "=>", "'Cyan bluish gray'", ",", "'color'", "=>", "'#abb8c3'", "]", ",", "[", "'name'", "=>", "'Very dark gray'", ",", "'color'", "=>", "'#313131'", "]", "]", ";", "return", "array_map", "(", "function", "(", "array", "$", "color", ")", "{", "return", "[", "'name'", "=>", "function_exists", "(", "'__'", ")", "?", "__", "(", "$", "color", "[", "'name'", "]", ",", "Application", "::", "TEXTDOMAIN", ")", ":", "$", "color", "[", "'name'", "]", ",", "'color'", "=>", "$", "color", "[", "'color'", "]", "]", ";", "}", ",", "$", "colors", ")", ";", "}" ]
Return a list of default colors for the field. @return array
[ "Return", "a", "list", "of", "default", "colors", "for", "the", "field", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/Fields/Types/ColorType.php#L78-L133
train
themosis/framework
src/Taxonomy/TaxonomyServiceProvider.php
TaxonomyServiceProvider.registerTaxonomyField
protected function registerTaxonomyField() { $this->app->bind('taxonomy.field', function ($app) { $viewFactory = $app['view']; $viewFactory->addLocation(__DIR__.'/views'); return new TaxonomyField( new TaxonomyFieldRepository(), $viewFactory, $app['validator'], $app['action'] ); }); }
php
protected function registerTaxonomyField() { $this->app->bind('taxonomy.field', function ($app) { $viewFactory = $app['view']; $viewFactory->addLocation(__DIR__.'/views'); return new TaxonomyField( new TaxonomyFieldRepository(), $viewFactory, $app['validator'], $app['action'] ); }); }
[ "protected", "function", "registerTaxonomyField", "(", ")", "{", "$", "this", "->", "app", "->", "bind", "(", "'taxonomy.field'", ",", "function", "(", "$", "app", ")", "{", "$", "viewFactory", "=", "$", "app", "[", "'view'", "]", ";", "$", "viewFactory", "->", "addLocation", "(", "__DIR__", ".", "'/views'", ")", ";", "return", "new", "TaxonomyField", "(", "new", "TaxonomyFieldRepository", "(", ")", ",", "$", "viewFactory", ",", "$", "app", "[", "'validator'", "]", ",", "$", "app", "[", "'action'", "]", ")", ";", "}", ")", ";", "}" ]
Register taxonomy field.
[ "Register", "taxonomy", "field", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Taxonomy/TaxonomyServiceProvider.php#L28-L41
train
themosis/framework
src/Core/Support/WordPressUrl.php
WordPressUrl.formatUrl
public function formatUrl(string $url, string $delimiter = 'wp-admin', string $fragment = 'cms') { /* * If there is already a "cms" fragment in the URI, * just return the URL. */ if (strrpos($url, $fragment) !== false) { return $url; } /* * The network admin URL is missing the "cms" fragment. * Let's add it. */ $fragments = explode($delimiter, $url); /* * Insert in the middle the cms fragment appended with the wp-admin delimiter. */ array_splice($fragments, 1, 0, "{$fragment}/{$delimiter}"); /* * Build the URL by reducing (concatenating) all fragments. * This appends each fragment to the previous one. */ $url = array_reduce($fragments, function ($carry, $item) { return $carry.=$item; }); return $url; }
php
public function formatUrl(string $url, string $delimiter = 'wp-admin', string $fragment = 'cms') { /* * If there is already a "cms" fragment in the URI, * just return the URL. */ if (strrpos($url, $fragment) !== false) { return $url; } /* * The network admin URL is missing the "cms" fragment. * Let's add it. */ $fragments = explode($delimiter, $url); /* * Insert in the middle the cms fragment appended with the wp-admin delimiter. */ array_splice($fragments, 1, 0, "{$fragment}/{$delimiter}"); /* * Build the URL by reducing (concatenating) all fragments. * This appends each fragment to the previous one. */ $url = array_reduce($fragments, function ($carry, $item) { return $carry.=$item; }); return $url; }
[ "public", "function", "formatUrl", "(", "string", "$", "url", ",", "string", "$", "delimiter", "=", "'wp-admin'", ",", "string", "$", "fragment", "=", "'cms'", ")", "{", "/*\n * If there is already a \"cms\" fragment in the URI,\n * just return the URL.\n */", "if", "(", "strrpos", "(", "$", "url", ",", "$", "fragment", ")", "!==", "false", ")", "{", "return", "$", "url", ";", "}", "/*\n * The network admin URL is missing the \"cms\" fragment.\n * Let's add it.\n */", "$", "fragments", "=", "explode", "(", "$", "delimiter", ",", "$", "url", ")", ";", "/*\n * Insert in the middle the cms fragment appended with the wp-admin delimiter.\n */", "array_splice", "(", "$", "fragments", ",", "1", ",", "0", ",", "\"{$fragment}/{$delimiter}\"", ")", ";", "/*\n * Build the URL by reducing (concatenating) all fragments.\n * This appends each fragment to the previous one.\n */", "$", "url", "=", "array_reduce", "(", "$", "fragments", ",", "function", "(", "$", "carry", ",", "$", "item", ")", "{", "return", "$", "carry", ".=", "$", "item", ";", "}", ")", ";", "return", "$", "url", ";", "}" ]
Format the URL. If the URL is missing the WordPress directory fragment, it adds it before the common delimiter. @param string $url @param string $delimiter @param string $fragment @return string
[ "Format", "the", "URL", ".", "If", "the", "URL", "is", "missing", "the", "WordPress", "directory", "fragment", "it", "adds", "it", "before", "the", "common", "delimiter", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Support/WordPressUrl.php#L17-L47
train
themosis/framework
src/Core/Support/WordPressUrl.php
WordPressUrl.formatNetworkUrl
public function formatNetworkUrl(string $url, string $delimiter = 'wp-admin', string $fragment = 'cms') { return $this->formatUrl($url, $delimiter, $fragment); }
php
public function formatNetworkUrl(string $url, string $delimiter = 'wp-admin', string $fragment = 'cms') { return $this->formatUrl($url, $delimiter, $fragment); }
[ "public", "function", "formatNetworkUrl", "(", "string", "$", "url", ",", "string", "$", "delimiter", "=", "'wp-admin'", ",", "string", "$", "fragment", "=", "'cms'", ")", "{", "return", "$", "this", "->", "formatUrl", "(", "$", "url", ",", "$", "delimiter", ",", "$", "fragment", ")", ";", "}" ]
Format the network URL. If the URL is missing the WordPress directory fragment, it adds it before the common delimiter. @param string $url @param string $delimiter @param string $fragment @return string
[ "Format", "the", "network", "URL", ".", "If", "the", "URL", "is", "missing", "the", "WordPress", "directory", "fragment", "it", "adds", "it", "before", "the", "common", "delimiter", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Support/WordPressUrl.php#L104-L107
train
themosis/framework
src/PostType/PostType.php
PostType.setLabels
public function setLabels(array $labels): PostTypeInterface { if (isset($this->args['labels'])) { $this->args['labels'] = array_merge($this->args['labels'], $labels); } else { $this->args['labels'] = $labels; } return $this; }
php
public function setLabels(array $labels): PostTypeInterface { if (isset($this->args['labels'])) { $this->args['labels'] = array_merge($this->args['labels'], $labels); } else { $this->args['labels'] = $labels; } return $this; }
[ "public", "function", "setLabels", "(", "array", "$", "labels", ")", ":", "PostTypeInterface", "{", "if", "(", "isset", "(", "$", "this", "->", "args", "[", "'labels'", "]", ")", ")", "{", "$", "this", "->", "args", "[", "'labels'", "]", "=", "array_merge", "(", "$", "this", "->", "args", "[", "'labels'", "]", ",", "$", "labels", ")", ";", "}", "else", "{", "$", "this", "->", "args", "[", "'labels'", "]", "=", "$", "labels", ";", "}", "return", "$", "this", ";", "}" ]
Set the post type labels. @param array $labels @return PostTypeInterface
[ "Set", "the", "post", "type", "labels", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/PostType/PostType.php#L59-L68
train
themosis/framework
src/PostType/PostType.php
PostType.setArguments
public function setArguments(array $args): PostTypeInterface { $this->args = array_merge($this->args, $args); return $this; }
php
public function setArguments(array $args): PostTypeInterface { $this->args = array_merge($this->args, $args); return $this; }
[ "public", "function", "setArguments", "(", "array", "$", "args", ")", ":", "PostTypeInterface", "{", "$", "this", "->", "args", "=", "array_merge", "(", "$", "this", "->", "args", ",", "$", "args", ")", ";", "return", "$", "this", ";", "}" ]
Set the post type arguments. @param array $args @return PostTypeInterface
[ "Set", "the", "post", "type", "arguments", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/PostType/PostType.php#L101-L106
train
themosis/framework
src/PostType/PostType.php
PostType.register
public function register() { $this->instance = register_post_type($this->slug, $this->getArguments()); $this->registerStatus(); }
php
public function register() { $this->instance = register_post_type($this->slug, $this->getArguments()); $this->registerStatus(); }
[ "public", "function", "register", "(", ")", "{", "$", "this", "->", "instance", "=", "register_post_type", "(", "$", "this", "->", "slug", ",", "$", "this", "->", "getArguments", "(", ")", ")", ";", "$", "this", "->", "registerStatus", "(", ")", ";", "}" ]
Register post type hook callback.
[ "Register", "post", "type", "hook", "callback", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/PostType/PostType.php#L182-L186
train
themosis/framework
src/PostType/PostType.php
PostType.setTitlePlaceholder
public function setTitlePlaceholder(string $title): PostTypeInterface { $this->filter->add('enter_title_here', function ($default) use ($title) { $screen = get_current_screen(); if ($this->slug === $screen->post_type) { return $title; } return $default; }); return $this; }
php
public function setTitlePlaceholder(string $title): PostTypeInterface { $this->filter->add('enter_title_here', function ($default) use ($title) { $screen = get_current_screen(); if ($this->slug === $screen->post_type) { return $title; } return $default; }); return $this; }
[ "public", "function", "setTitlePlaceholder", "(", "string", "$", "title", ")", ":", "PostTypeInterface", "{", "$", "this", "->", "filter", "->", "add", "(", "'enter_title_here'", ",", "function", "(", "$", "default", ")", "use", "(", "$", "title", ")", "{", "$", "screen", "=", "get_current_screen", "(", ")", ";", "if", "(", "$", "this", "->", "slug", "===", "$", "screen", "->", "post_type", ")", "{", "return", "$", "title", ";", "}", "return", "$", "default", ";", "}", ")", ";", "return", "$", "this", ";", "}" ]
Set the post type title input placeholder. @param string $title @return PostTypeInterface
[ "Set", "the", "post", "type", "title", "input", "placeholder", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/PostType/PostType.php#L195-L208
train
themosis/framework
src/PostType/PostType.php
PostType.registerStatus
protected function registerStatus() { if (empty($this->status)) { return; } foreach ($this->status as $key => $args) { register_post_status($key, $args); } Metabox::make('themosis_publish', $this->slug) ->setTitle(__('Publish')) ->setContext('side') ->setPriority('core') ->setCallback(function ($args) { echo view('_themosisPublishMetabox', [ 'statuses' => $this->status, '__post' => $args['post'] ]); }) ->set(); }
php
protected function registerStatus() { if (empty($this->status)) { return; } foreach ($this->status as $key => $args) { register_post_status($key, $args); } Metabox::make('themosis_publish', $this->slug) ->setTitle(__('Publish')) ->setContext('side') ->setPriority('core') ->setCallback(function ($args) { echo view('_themosisPublishMetabox', [ 'statuses' => $this->status, '__post' => $args['post'] ]); }) ->set(); }
[ "protected", "function", "registerStatus", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "status", ")", ")", "{", "return", ";", "}", "foreach", "(", "$", "this", "->", "status", "as", "$", "key", "=>", "$", "args", ")", "{", "register_post_status", "(", "$", "key", ",", "$", "args", ")", ";", "}", "Metabox", "::", "make", "(", "'themosis_publish'", ",", "$", "this", "->", "slug", ")", "->", "setTitle", "(", "__", "(", "'Publish'", ")", ")", "->", "setContext", "(", "'side'", ")", "->", "setPriority", "(", "'core'", ")", "->", "setCallback", "(", "function", "(", "$", "args", ")", "{", "echo", "view", "(", "'_themosisPublishMetabox'", ",", "[", "'statuses'", "=>", "$", "this", "->", "status", ",", "'__post'", "=>", "$", "args", "[", "'post'", "]", "]", ")", ";", "}", ")", "->", "set", "(", ")", ";", "}" ]
Register the custom status if any.
[ "Register", "the", "custom", "status", "if", "any", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/PostType/PostType.php#L213-L234
train
themosis/framework
src/PostType/PostType.php
PostType.status
public function status($status, array $args = []): PostTypeInterface { if (is_array($status)) { foreach ($status as $key => $params) { if (is_int($key)) { $this->status($params); } elseif (is_string($key) && is_array($params)) { $this->status($key, $params); } } return $this; } $this->prepareStatus($status, $args); return $this; }
php
public function status($status, array $args = []): PostTypeInterface { if (is_array($status)) { foreach ($status as $key => $params) { if (is_int($key)) { $this->status($params); } elseif (is_string($key) && is_array($params)) { $this->status($key, $params); } } return $this; } $this->prepareStatus($status, $args); return $this; }
[ "public", "function", "status", "(", "$", "status", ",", "array", "$", "args", "=", "[", "]", ")", ":", "PostTypeInterface", "{", "if", "(", "is_array", "(", "$", "status", ")", ")", "{", "foreach", "(", "$", "status", "as", "$", "key", "=>", "$", "params", ")", "{", "if", "(", "is_int", "(", "$", "key", ")", ")", "{", "$", "this", "->", "status", "(", "$", "params", ")", ";", "}", "elseif", "(", "is_string", "(", "$", "key", ")", "&&", "is_array", "(", "$", "params", ")", ")", "{", "$", "this", "->", "status", "(", "$", "key", ",", "$", "params", ")", ";", "}", "}", "return", "$", "this", ";", "}", "$", "this", "->", "prepareStatus", "(", "$", "status", ",", "$", "args", ")", ";", "return", "$", "this", ";", "}" ]
Set post type custom status. @param array|string $status @param array $args @return PostTypeInterface
[ "Set", "post", "type", "custom", "status", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/PostType/PostType.php#L244-L261
train
themosis/framework
src/PostType/PostType.php
PostType.prepareStatus
protected function prepareStatus(string $status, array $args) { $this->status[$status] = $this->parseStatusArguments($status, $args); // Remove default publish metabox. $this->action->add('add_meta_boxes', function () { remove_meta_box('submitdiv', $this->slug, 'side'); }); // Apply selected status on save. $this->filter->add([ 'pre_post_status', 'status_save_pre' ], [$this, 'applyStatus']); // Expose post type status for JS use. $this->filter->add('themosis_admin_global', function ($data) { $status['draft'] = $this->parseStatusArguments('draft', [ 'publish_text' => __('Save Draft') ]); $data['post_types'][$this->slug] = ['statuses' => array_merge($status, $this->status)]; return $data; }); // Reorder the list of statuses on the list table. // Put the "trash" item as the last one. $this->filter->add("views_edit-{$this->slug}", function ($views) { if (array_key_exists('trash', $views)) { $trash = $views['trash']; unset($views['trash']); end($views); $views['trash'] = $trash; } return $views; }); }
php
protected function prepareStatus(string $status, array $args) { $this->status[$status] = $this->parseStatusArguments($status, $args); // Remove default publish metabox. $this->action->add('add_meta_boxes', function () { remove_meta_box('submitdiv', $this->slug, 'side'); }); // Apply selected status on save. $this->filter->add([ 'pre_post_status', 'status_save_pre' ], [$this, 'applyStatus']); // Expose post type status for JS use. $this->filter->add('themosis_admin_global', function ($data) { $status['draft'] = $this->parseStatusArguments('draft', [ 'publish_text' => __('Save Draft') ]); $data['post_types'][$this->slug] = ['statuses' => array_merge($status, $this->status)]; return $data; }); // Reorder the list of statuses on the list table. // Put the "trash" item as the last one. $this->filter->add("views_edit-{$this->slug}", function ($views) { if (array_key_exists('trash', $views)) { $trash = $views['trash']; unset($views['trash']); end($views); $views['trash'] = $trash; } return $views; }); }
[ "protected", "function", "prepareStatus", "(", "string", "$", "status", ",", "array", "$", "args", ")", "{", "$", "this", "->", "status", "[", "$", "status", "]", "=", "$", "this", "->", "parseStatusArguments", "(", "$", "status", ",", "$", "args", ")", ";", "// Remove default publish metabox.", "$", "this", "->", "action", "->", "add", "(", "'add_meta_boxes'", ",", "function", "(", ")", "{", "remove_meta_box", "(", "'submitdiv'", ",", "$", "this", "->", "slug", ",", "'side'", ")", ";", "}", ")", ";", "// Apply selected status on save.", "$", "this", "->", "filter", "->", "add", "(", "[", "'pre_post_status'", ",", "'status_save_pre'", "]", ",", "[", "$", "this", ",", "'applyStatus'", "]", ")", ";", "// Expose post type status for JS use.", "$", "this", "->", "filter", "->", "add", "(", "'themosis_admin_global'", ",", "function", "(", "$", "data", ")", "{", "$", "status", "[", "'draft'", "]", "=", "$", "this", "->", "parseStatusArguments", "(", "'draft'", ",", "[", "'publish_text'", "=>", "__", "(", "'Save Draft'", ")", "]", ")", ";", "$", "data", "[", "'post_types'", "]", "[", "$", "this", "->", "slug", "]", "=", "[", "'statuses'", "=>", "array_merge", "(", "$", "status", ",", "$", "this", "->", "status", ")", "]", ";", "return", "$", "data", ";", "}", ")", ";", "// Reorder the list of statuses on the list table.", "// Put the \"trash\" item as the last one.", "$", "this", "->", "filter", "->", "add", "(", "\"views_edit-{$this->slug}\"", ",", "function", "(", "$", "views", ")", "{", "if", "(", "array_key_exists", "(", "'trash'", ",", "$", "views", ")", ")", "{", "$", "trash", "=", "$", "views", "[", "'trash'", "]", ";", "unset", "(", "$", "views", "[", "'trash'", "]", ")", ";", "end", "(", "$", "views", ")", ";", "$", "views", "[", "'trash'", "]", "=", "$", "trash", ";", "}", "return", "$", "views", ";", "}", ")", ";", "}" ]
Register custom post type status. @param string $status @param array $args
[ "Register", "custom", "post", "type", "status", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/PostType/PostType.php#L279-L317
train
themosis/framework
src/PostType/PostType.php
PostType.parseStatusArguments
protected function parseStatusArguments(string $status, array $args): array { $name = ucfirst($status); return wp_parse_args($args, [ 'label' => $name, 'public' => true, 'exclude_from_search' => false, 'show_in_admin_all_list' => true, 'show_in_admin_status_list' => true, 'label_count' => _n_noop( $name.' <span class="count">(%s)</span>', $name.' <span class="count">(%s)</span>' ), 'publish_text' => __('Apply Changes') ]); }
php
protected function parseStatusArguments(string $status, array $args): array { $name = ucfirst($status); return wp_parse_args($args, [ 'label' => $name, 'public' => true, 'exclude_from_search' => false, 'show_in_admin_all_list' => true, 'show_in_admin_status_list' => true, 'label_count' => _n_noop( $name.' <span class="count">(%s)</span>', $name.' <span class="count">(%s)</span>' ), 'publish_text' => __('Apply Changes') ]); }
[ "protected", "function", "parseStatusArguments", "(", "string", "$", "status", ",", "array", "$", "args", ")", ":", "array", "{", "$", "name", "=", "ucfirst", "(", "$", "status", ")", ";", "return", "wp_parse_args", "(", "$", "args", ",", "[", "'label'", "=>", "$", "name", ",", "'public'", "=>", "true", ",", "'exclude_from_search'", "=>", "false", ",", "'show_in_admin_all_list'", "=>", "true", ",", "'show_in_admin_status_list'", "=>", "true", ",", "'label_count'", "=>", "_n_noop", "(", "$", "name", ".", "' <span class=\"count\">(%s)</span>'", ",", "$", "name", ".", "' <span class=\"count\">(%s)</span>'", ")", ",", "'publish_text'", "=>", "__", "(", "'Apply Changes'", ")", "]", ")", ";", "}" ]
Parse the status arguments. @param string $status @param array $args @return array
[ "Parse", "the", "status", "arguments", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/PostType/PostType.php#L327-L343
train
themosis/framework
src/PostType/PostType.php
PostType.applyStatus
public function applyStatus(string $value) { if (isset($_POST['post_type']) && $this->slug === $_POST['post_type'] && ! empty($this->status)) { if ((isset($_POST['post_status']) && 'publish' === $_POST['post_status']) && (isset($_REQUEST['post_status']) && 'draft' === $_REQUEST['post_status'])) { // New post with draft status as default and "publish" button is clicked. // Let's set to first registered status. $statuses = array_keys($this->status); return esc_attr(array_shift($statuses)); } elseif (isset($_REQUEST['post_status']) && ! empty($_REQUEST['post_status'])) { // In case of a quickedit ajax save call, check the value of the "_status" // select tag before processing default post_status. if (isset($_POST['_status']) && ! empty($_POST['_status'])) { return esc_attr($_POST['_status']); } // Else, simply apply the selected custom status value returned // from the edit screen of the custom post type. return esc_attr($_REQUEST['post_status']); } } return esc_attr($value); }
php
public function applyStatus(string $value) { if (isset($_POST['post_type']) && $this->slug === $_POST['post_type'] && ! empty($this->status)) { if ((isset($_POST['post_status']) && 'publish' === $_POST['post_status']) && (isset($_REQUEST['post_status']) && 'draft' === $_REQUEST['post_status'])) { // New post with draft status as default and "publish" button is clicked. // Let's set to first registered status. $statuses = array_keys($this->status); return esc_attr(array_shift($statuses)); } elseif (isset($_REQUEST['post_status']) && ! empty($_REQUEST['post_status'])) { // In case of a quickedit ajax save call, check the value of the "_status" // select tag before processing default post_status. if (isset($_POST['_status']) && ! empty($_POST['_status'])) { return esc_attr($_POST['_status']); } // Else, simply apply the selected custom status value returned // from the edit screen of the custom post type. return esc_attr($_REQUEST['post_status']); } } return esc_attr($value); }
[ "public", "function", "applyStatus", "(", "string", "$", "value", ")", "{", "if", "(", "isset", "(", "$", "_POST", "[", "'post_type'", "]", ")", "&&", "$", "this", "->", "slug", "===", "$", "_POST", "[", "'post_type'", "]", "&&", "!", "empty", "(", "$", "this", "->", "status", ")", ")", "{", "if", "(", "(", "isset", "(", "$", "_POST", "[", "'post_status'", "]", ")", "&&", "'publish'", "===", "$", "_POST", "[", "'post_status'", "]", ")", "&&", "(", "isset", "(", "$", "_REQUEST", "[", "'post_status'", "]", ")", "&&", "'draft'", "===", "$", "_REQUEST", "[", "'post_status'", "]", ")", ")", "{", "// New post with draft status as default and \"publish\" button is clicked.", "// Let's set to first registered status.", "$", "statuses", "=", "array_keys", "(", "$", "this", "->", "status", ")", ";", "return", "esc_attr", "(", "array_shift", "(", "$", "statuses", ")", ")", ";", "}", "elseif", "(", "isset", "(", "$", "_REQUEST", "[", "'post_status'", "]", ")", "&&", "!", "empty", "(", "$", "_REQUEST", "[", "'post_status'", "]", ")", ")", "{", "// In case of a quickedit ajax save call, check the value of the \"_status\"", "// select tag before processing default post_status.", "if", "(", "isset", "(", "$", "_POST", "[", "'_status'", "]", ")", "&&", "!", "empty", "(", "$", "_POST", "[", "'_status'", "]", ")", ")", "{", "return", "esc_attr", "(", "$", "_POST", "[", "'_status'", "]", ")", ";", "}", "// Else, simply apply the selected custom status value returned", "// from the edit screen of the custom post type.", "return", "esc_attr", "(", "$", "_REQUEST", "[", "'post_status'", "]", ")", ";", "}", "}", "return", "esc_attr", "(", "$", "value", ")", ";", "}" ]
Apply the selected status on post save. @param string $value The translated value by WordPress ("publish"). @return string
[ "Apply", "the", "selected", "status", "on", "post", "save", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/PostType/PostType.php#L352-L376
train
themosis/framework
src/Route/Router.php
Router.setConditions
public function setConditions(array $conditions = []) { $config = $this->container->has('config') ? $this->container->make('config') : null; if (! is_null($config)) { $this->conditions = array_merge( $config->get('app.conditions', []), $conditions ); } else { $this->conditions = $conditions; } }
php
public function setConditions(array $conditions = []) { $config = $this->container->has('config') ? $this->container->make('config') : null; if (! is_null($config)) { $this->conditions = array_merge( $config->get('app.conditions', []), $conditions ); } else { $this->conditions = $conditions; } }
[ "public", "function", "setConditions", "(", "array", "$", "conditions", "=", "[", "]", ")", "{", "$", "config", "=", "$", "this", "->", "container", "->", "has", "(", "'config'", ")", "?", "$", "this", "->", "container", "->", "make", "(", "'config'", ")", ":", "null", ";", "if", "(", "!", "is_null", "(", "$", "config", ")", ")", "{", "$", "this", "->", "conditions", "=", "array_merge", "(", "$", "config", "->", "get", "(", "'app.conditions'", ",", "[", "]", ")", ",", "$", "conditions", ")", ";", "}", "else", "{", "$", "this", "->", "conditions", "=", "$", "conditions", ";", "}", "}" ]
Setup WordPress conditions. @param array $conditions
[ "Setup", "WordPress", "conditions", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Route/Router.php#L78-L90
train
themosis/framework
src/Route/Router.php
Router.addWordPressBindings
public function addWordPressBindings($route) { global $post, $wp_query; foreach (compact('post', 'wp_query') as $key => $value) { $route->setParameter($key, $value); } return $route; }
php
public function addWordPressBindings($route) { global $post, $wp_query; foreach (compact('post', 'wp_query') as $key => $value) { $route->setParameter($key, $value); } return $route; }
[ "public", "function", "addWordPressBindings", "(", "$", "route", ")", "{", "global", "$", "post", ",", "$", "wp_query", ";", "foreach", "(", "compact", "(", "'post'", ",", "'wp_query'", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "route", "->", "setParameter", "(", "$", "key", ",", "$", "value", ")", ";", "}", "return", "$", "route", ";", "}" ]
Add WordPress default parameters if WordPress route. @param \Themosis\Route\Route $route @return \Themosis\Route\Route
[ "Add", "WordPress", "default", "parameters", "if", "WordPress", "route", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Route/Router.php#L99-L108
train
themosis/framework
src/Route/Router.php
Router.auth
public function auth(array $options = []) { // Authentication routes. $this->get('auth/login', 'Auth\LoginController@showLoginForm')->name('login'); $this->post('auth/login', 'Auth\LoginController@login'); $this->post('auth/logout', 'Auth\LoginController@logout')->name('logout'); // Registration routes. if ($options['register'] ?? true) { $this->get('auth/register', 'Auth\RegisterController@showRegistrationForm')->name('register'); $this->post('auth/register', 'Auth\RegisterController@register'); } // Password reset routes. if ($options['reset'] ?? true) { $this->resetPassword(); } // Email verifications routes. if ($options['verify'] ?? false) { $this->emailVerification(); } }
php
public function auth(array $options = []) { // Authentication routes. $this->get('auth/login', 'Auth\LoginController@showLoginForm')->name('login'); $this->post('auth/login', 'Auth\LoginController@login'); $this->post('auth/logout', 'Auth\LoginController@logout')->name('logout'); // Registration routes. if ($options['register'] ?? true) { $this->get('auth/register', 'Auth\RegisterController@showRegistrationForm')->name('register'); $this->post('auth/register', 'Auth\RegisterController@register'); } // Password reset routes. if ($options['reset'] ?? true) { $this->resetPassword(); } // Email verifications routes. if ($options['verify'] ?? false) { $this->emailVerification(); } }
[ "public", "function", "auth", "(", "array", "$", "options", "=", "[", "]", ")", "{", "// Authentication routes.", "$", "this", "->", "get", "(", "'auth/login'", ",", "'Auth\\LoginController@showLoginForm'", ")", "->", "name", "(", "'login'", ")", ";", "$", "this", "->", "post", "(", "'auth/login'", ",", "'Auth\\LoginController@login'", ")", ";", "$", "this", "->", "post", "(", "'auth/logout'", ",", "'Auth\\LoginController@logout'", ")", "->", "name", "(", "'logout'", ")", ";", "// Registration routes.", "if", "(", "$", "options", "[", "'register'", "]", "??", "true", ")", "{", "$", "this", "->", "get", "(", "'auth/register'", ",", "'Auth\\RegisterController@showRegistrationForm'", ")", "->", "name", "(", "'register'", ")", ";", "$", "this", "->", "post", "(", "'auth/register'", ",", "'Auth\\RegisterController@register'", ")", ";", "}", "// Password reset routes.", "if", "(", "$", "options", "[", "'reset'", "]", "??", "true", ")", "{", "$", "this", "->", "resetPassword", "(", ")", ";", "}", "// Email verifications routes.", "if", "(", "$", "options", "[", "'verify'", "]", "??", "false", ")", "{", "$", "this", "->", "emailVerification", "(", ")", ";", "}", "}" ]
Register the typical authentication routes for an application. Avoid WordPress default endpoints. @param array $options
[ "Register", "the", "typical", "authentication", "routes", "for", "an", "application", ".", "Avoid", "WordPress", "default", "endpoints", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Route/Router.php#L116-L138
train
themosis/framework
src/Forms/Resources/Transformers/FormTransformer.php
FormTransformer.transform
public function transform(FieldTypeInterface $form) { return [ 'attributes' => $form->getAttributes(), 'flush' => $form->getOption('flush', true), 'locale' => $form->getLocale(), 'nonce' => $form->getOption('nonce', '_themosisnonce'), 'referer' => $form->getOption('referer', true), 'tags' => $form->getOption('tags', true), 'theme' => $form->getOption('theme', 'themosis'), 'type' => $form->getType(), 'validation' => [ 'errors' => $form->getOption('errors', true), 'isValid' => $form->isValid() ] ]; }
php
public function transform(FieldTypeInterface $form) { return [ 'attributes' => $form->getAttributes(), 'flush' => $form->getOption('flush', true), 'locale' => $form->getLocale(), 'nonce' => $form->getOption('nonce', '_themosisnonce'), 'referer' => $form->getOption('referer', true), 'tags' => $form->getOption('tags', true), 'theme' => $form->getOption('theme', 'themosis'), 'type' => $form->getType(), 'validation' => [ 'errors' => $form->getOption('errors', true), 'isValid' => $form->isValid() ] ]; }
[ "public", "function", "transform", "(", "FieldTypeInterface", "$", "form", ")", "{", "return", "[", "'attributes'", "=>", "$", "form", "->", "getAttributes", "(", ")", ",", "'flush'", "=>", "$", "form", "->", "getOption", "(", "'flush'", ",", "true", ")", ",", "'locale'", "=>", "$", "form", "->", "getLocale", "(", ")", ",", "'nonce'", "=>", "$", "form", "->", "getOption", "(", "'nonce'", ",", "'_themosisnonce'", ")", ",", "'referer'", "=>", "$", "form", "->", "getOption", "(", "'referer'", ",", "true", ")", ",", "'tags'", "=>", "$", "form", "->", "getOption", "(", "'tags'", ",", "true", ")", ",", "'theme'", "=>", "$", "form", "->", "getOption", "(", "'theme'", ",", "'themosis'", ")", ",", "'type'", "=>", "$", "form", "->", "getType", "(", ")", ",", "'validation'", "=>", "[", "'errors'", "=>", "$", "form", "->", "getOption", "(", "'errors'", ",", "true", ")", ",", "'isValid'", "=>", "$", "form", "->", "isValid", "(", ")", "]", "]", ";", "}" ]
Transform single form. @param FieldTypeInterface $form @return array
[ "Transform", "single", "form", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/Resources/Transformers/FormTransformer.php#L27-L43
train
themosis/framework
src/Forms/Resources/Transformers/FormTransformer.php
FormTransformer.includeGroups
public function includeGroups(FieldTypeInterface $form) { /** @var FieldTypeInterface|FormInterface $form */ return $this->collection( $form->repository()->getGroups(), $form->getResourceTransformerFactory()->make('GroupTransformer') ); }
php
public function includeGroups(FieldTypeInterface $form) { /** @var FieldTypeInterface|FormInterface $form */ return $this->collection( $form->repository()->getGroups(), $form->getResourceTransformerFactory()->make('GroupTransformer') ); }
[ "public", "function", "includeGroups", "(", "FieldTypeInterface", "$", "form", ")", "{", "/** @var FieldTypeInterface|FormInterface $form */", "return", "$", "this", "->", "collection", "(", "$", "form", "->", "repository", "(", ")", "->", "getGroups", "(", ")", ",", "$", "form", "->", "getResourceTransformerFactory", "(", ")", "->", "make", "(", "'GroupTransformer'", ")", ")", ";", "}" ]
Include "groups" property to resource. @param FieldTypeInterface $form @return \League\Fractal\Resource\Collection
[ "Include", "groups", "property", "to", "resource", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/Resources/Transformers/FormTransformer.php#L74-L81
train
themosis/framework
src/Asset/Asset.php
Asset.setType
public function setType(string $type): AssetInterface { $path = $this->file->isExternal() ? $this->getUrl() : $this->getPath(); $this->file->setType($path, $type); return $this; }
php
public function setType(string $type): AssetInterface { $path = $this->file->isExternal() ? $this->getUrl() : $this->getPath(); $this->file->setType($path, $type); return $this; }
[ "public", "function", "setType", "(", "string", "$", "type", ")", ":", "AssetInterface", "{", "$", "path", "=", "$", "this", "->", "file", "->", "isExternal", "(", ")", "?", "$", "this", "->", "getUrl", "(", ")", ":", "$", "this", "->", "getPath", "(", ")", ";", "$", "this", "->", "file", "->", "setType", "(", "$", "path", ",", "$", "type", ")", ";", "return", "$", "this", ";", "}" ]
Set the asset type. Override the auto-discovered type if any. @param string $type @return AssetInterface
[ "Set", "the", "asset", "type", ".", "Override", "the", "auto", "-", "discovered", "type", "if", "any", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Asset/Asset.php#L192-L199
train
themosis/framework
src/Asset/Asset.php
Asset.setArgument
public function setArgument($arg = null): AssetInterface { if (! is_null($arg)) { $this->argument = $arg; return $this; } // If no argument is passed but we have its type // then let's define some defaults. if ('style' === $this->getType()) { $this->argument = 'all'; } if ('script' === $this->getType()) { $this->argument = true; } return $this; }
php
public function setArgument($arg = null): AssetInterface { if (! is_null($arg)) { $this->argument = $arg; return $this; } // If no argument is passed but we have its type // then let's define some defaults. if ('style' === $this->getType()) { $this->argument = 'all'; } if ('script' === $this->getType()) { $this->argument = true; } return $this; }
[ "public", "function", "setArgument", "(", "$", "arg", "=", "null", ")", ":", "AssetInterface", "{", "if", "(", "!", "is_null", "(", "$", "arg", ")", ")", "{", "$", "this", "->", "argument", "=", "$", "arg", ";", "return", "$", "this", ";", "}", "// If no argument is passed but we have its type", "// then let's define some defaults.", "if", "(", "'style'", "===", "$", "this", "->", "getType", "(", ")", ")", "{", "$", "this", "->", "argument", "=", "'all'", ";", "}", "if", "(", "'script'", "===", "$", "this", "->", "getType", "(", ")", ")", "{", "$", "this", "->", "argument", "=", "true", ";", "}", "return", "$", "this", ";", "}" ]
Set the asset argument. @param bool|string $arg @return AssetInterface
[ "Set", "the", "asset", "argument", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Asset/Asset.php#L228-L247
train
themosis/framework
src/Asset/Asset.php
Asset.to
public function to($locations = 'front'): AssetInterface { if (is_string($locations)) { $locations = [$locations]; } foreach ($locations as $location) { $hook = array_search($location, $this->locations, true); if ($hook) { $this->install($hook); } } return $this; }
php
public function to($locations = 'front'): AssetInterface { if (is_string($locations)) { $locations = [$locations]; } foreach ($locations as $location) { $hook = array_search($location, $this->locations, true); if ($hook) { $this->install($hook); } } return $this; }
[ "public", "function", "to", "(", "$", "locations", "=", "'front'", ")", ":", "AssetInterface", "{", "if", "(", "is_string", "(", "$", "locations", ")", ")", "{", "$", "locations", "=", "[", "$", "locations", "]", ";", "}", "foreach", "(", "$", "locations", "as", "$", "location", ")", "{", "$", "hook", "=", "array_search", "(", "$", "location", ",", "$", "this", "->", "locations", ",", "true", ")", ";", "if", "(", "$", "hook", ")", "{", "$", "this", "->", "install", "(", "$", "hook", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
Load the asset on the defined area. Default to front-end. @param string|array $locations @return AssetInterface
[ "Load", "the", "asset", "on", "the", "defined", "area", ".", "Default", "to", "front", "-", "end", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Asset/Asset.php#L256-L271
train
themosis/framework
src/Asset/Asset.php
Asset.enqueue
public function enqueue() { if (is_null($this->getType())) { throw new AssetException('The asset must have a type defined. Null given.'); } if ('script' === $this->getType()) { $this->enqueueScript(); } else { $this->enqueueStyle(); } }
php
public function enqueue() { if (is_null($this->getType())) { throw new AssetException('The asset must have a type defined. Null given.'); } if ('script' === $this->getType()) { $this->enqueueScript(); } else { $this->enqueueStyle(); } }
[ "public", "function", "enqueue", "(", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "getType", "(", ")", ")", ")", "{", "throw", "new", "AssetException", "(", "'The asset must have a type defined. Null given.'", ")", ";", "}", "if", "(", "'script'", "===", "$", "this", "->", "getType", "(", ")", ")", "{", "$", "this", "->", "enqueueScript", "(", ")", ";", "}", "else", "{", "$", "this", "->", "enqueueStyle", "(", ")", ";", "}", "}" ]
Enqueue asset.
[ "Enqueue", "asset", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Asset/Asset.php#L286-L297
train
themosis/framework
src/Asset/Asset.php
Asset.enqueueScript
protected function enqueueScript() { wp_enqueue_script( $this->getHandle(), $this->getUrl(), $this->getDependencies(), $this->getVersion(), $this->getArgument() ); if (! empty($this->localize)) { foreach ($this->localize as $name => $data) { wp_localize_script($this->getHandle(), $name, $data); } } if (! empty($this->inline)) { foreach ($this->inline as $code) { wp_add_inline_script($this->getHandle(), $code['code'], $code['position']); } } }
php
protected function enqueueScript() { wp_enqueue_script( $this->getHandle(), $this->getUrl(), $this->getDependencies(), $this->getVersion(), $this->getArgument() ); if (! empty($this->localize)) { foreach ($this->localize as $name => $data) { wp_localize_script($this->getHandle(), $name, $data); } } if (! empty($this->inline)) { foreach ($this->inline as $code) { wp_add_inline_script($this->getHandle(), $code['code'], $code['position']); } } }
[ "protected", "function", "enqueueScript", "(", ")", "{", "wp_enqueue_script", "(", "$", "this", "->", "getHandle", "(", ")", ",", "$", "this", "->", "getUrl", "(", ")", ",", "$", "this", "->", "getDependencies", "(", ")", ",", "$", "this", "->", "getVersion", "(", ")", ",", "$", "this", "->", "getArgument", "(", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "localize", ")", ")", "{", "foreach", "(", "$", "this", "->", "localize", "as", "$", "name", "=>", "$", "data", ")", "{", "wp_localize_script", "(", "$", "this", "->", "getHandle", "(", ")", ",", "$", "name", ",", "$", "data", ")", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "inline", ")", ")", "{", "foreach", "(", "$", "this", "->", "inline", "as", "$", "code", ")", "{", "wp_add_inline_script", "(", "$", "this", "->", "getHandle", "(", ")", ",", "$", "code", "[", "'code'", "]", ",", "$", "code", "[", "'position'", "]", ")", ";", "}", "}", "}" ]
Enqueue a script asset.
[ "Enqueue", "a", "script", "asset", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Asset/Asset.php#L302-L323
train
themosis/framework
src/Asset/Asset.php
Asset.enqueueStyle
protected function enqueueStyle() { wp_enqueue_style( $this->getHandle(), $this->getUrl(), $this->getDependencies(), $this->getVersion(), $this->getArgument() ); if (! empty($this->inline)) { foreach ($this->inline as $code) { wp_add_inline_style($this->getHandle(), $code['code']); } } }
php
protected function enqueueStyle() { wp_enqueue_style( $this->getHandle(), $this->getUrl(), $this->getDependencies(), $this->getVersion(), $this->getArgument() ); if (! empty($this->inline)) { foreach ($this->inline as $code) { wp_add_inline_style($this->getHandle(), $code['code']); } } }
[ "protected", "function", "enqueueStyle", "(", ")", "{", "wp_enqueue_style", "(", "$", "this", "->", "getHandle", "(", ")", ",", "$", "this", "->", "getUrl", "(", ")", ",", "$", "this", "->", "getDependencies", "(", ")", ",", "$", "this", "->", "getVersion", "(", ")", ",", "$", "this", "->", "getArgument", "(", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "inline", ")", ")", "{", "foreach", "(", "$", "this", "->", "inline", "as", "$", "code", ")", "{", "wp_add_inline_style", "(", "$", "this", "->", "getHandle", "(", ")", ",", "$", "code", "[", "'code'", "]", ")", ";", "}", "}", "}" ]
Enqueue a style asset.
[ "Enqueue", "a", "style", "asset", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Asset/Asset.php#L328-L343
train
themosis/framework
src/Asset/Asset.php
Asset.localize
public function localize(string $name, array $data): AssetInterface { $this->localize[$name] = $data; return $this; }
php
public function localize(string $name, array $data): AssetInterface { $this->localize[$name] = $data; return $this; }
[ "public", "function", "localize", "(", "string", "$", "name", ",", "array", "$", "data", ")", ":", "AssetInterface", "{", "$", "this", "->", "localize", "[", "$", "name", "]", "=", "$", "data", ";", "return", "$", "this", ";", "}" ]
Localize the asset. @param string $name @param array $data @return AssetInterface
[ "Localize", "the", "asset", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Asset/Asset.php#L353-L358
train
themosis/framework
src/Asset/Asset.php
Asset.inline
public function inline(string $code, bool $after = true): AssetInterface { $this->inline[] = [ 'code' => $code, 'position' => $after ? 'after' : 'before' ]; return $this; }
php
public function inline(string $code, bool $after = true): AssetInterface { $this->inline[] = [ 'code' => $code, 'position' => $after ? 'after' : 'before' ]; return $this; }
[ "public", "function", "inline", "(", "string", "$", "code", ",", "bool", "$", "after", "=", "true", ")", ":", "AssetInterface", "{", "$", "this", "->", "inline", "[", "]", "=", "[", "'code'", "=>", "$", "code", ",", "'position'", "=>", "$", "after", "?", "'after'", ":", "'before'", "]", ";", "return", "$", "this", ";", "}" ]
Add asset inline code. @param string $code @param bool $after @return AssetInterface
[ "Add", "asset", "inline", "code", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Asset/Asset.php#L368-L376
train
themosis/framework
src/Asset/Asset.php
Asset.attributes
public function attributes(array $attributes): AssetInterface { if (is_null($this->getType())) { throw new AssetException('The asset must have a type.'); } $hook = 'script' === $this->getType() ? 'script_loader_tag' : 'style_loader_tag'; $key = strtolower(trim($this->getHandle())); $attributes = $this->html->attributes($attributes); $this->filter->add($hook, function ($tag, $handle) use ($attributes, $key) { if ($key !== $handle) { return $tag; } return preg_replace('/(src|href)(.+>)/', $attributes.'$1$2', $tag); }); return $this; }
php
public function attributes(array $attributes): AssetInterface { if (is_null($this->getType())) { throw new AssetException('The asset must have a type.'); } $hook = 'script' === $this->getType() ? 'script_loader_tag' : 'style_loader_tag'; $key = strtolower(trim($this->getHandle())); $attributes = $this->html->attributes($attributes); $this->filter->add($hook, function ($tag, $handle) use ($attributes, $key) { if ($key !== $handle) { return $tag; } return preg_replace('/(src|href)(.+>)/', $attributes.'$1$2', $tag); }); return $this; }
[ "public", "function", "attributes", "(", "array", "$", "attributes", ")", ":", "AssetInterface", "{", "if", "(", "is_null", "(", "$", "this", "->", "getType", "(", ")", ")", ")", "{", "throw", "new", "AssetException", "(", "'The asset must have a type.'", ")", ";", "}", "$", "hook", "=", "'script'", "===", "$", "this", "->", "getType", "(", ")", "?", "'script_loader_tag'", ":", "'style_loader_tag'", ";", "$", "key", "=", "strtolower", "(", "trim", "(", "$", "this", "->", "getHandle", "(", ")", ")", ")", ";", "$", "attributes", "=", "$", "this", "->", "html", "->", "attributes", "(", "$", "attributes", ")", ";", "$", "this", "->", "filter", "->", "add", "(", "$", "hook", ",", "function", "(", "$", "tag", ",", "$", "handle", ")", "use", "(", "$", "attributes", ",", "$", "key", ")", "{", "if", "(", "$", "key", "!==", "$", "handle", ")", "{", "return", "$", "tag", ";", "}", "return", "preg_replace", "(", "'/(src|href)(.+>)/'", ",", "$", "attributes", ".", "'$1$2'", ",", "$", "tag", ")", ";", "}", ")", ";", "return", "$", "this", ";", "}" ]
Add asset attributes. @param array $attributes @throws AssetException @return AssetInterface
[ "Add", "asset", "attributes", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Asset/Asset.php#L387-L406
train
themosis/framework
src/Taxonomy/TaxonomyFieldRepository.php
TaxonomyFieldRepository.add
public function add($field) { if (is_array($field)) { foreach ($field as $item) { $this->add($item); } } else { $this->fields[] = $field; } }
php
public function add($field) { if (is_array($field)) { foreach ($field as $item) { $this->add($item); } } else { $this->fields[] = $field; } }
[ "public", "function", "add", "(", "$", "field", ")", "{", "if", "(", "is_array", "(", "$", "field", ")", ")", "{", "foreach", "(", "$", "field", "as", "$", "item", ")", "{", "$", "this", "->", "add", "(", "$", "item", ")", ";", "}", "}", "else", "{", "$", "this", "->", "fields", "[", "]", "=", "$", "field", ";", "}", "}" ]
Add a field to the taxonomy. @param FieldTypeInterface|array $field
[ "Add", "a", "field", "to", "the", "taxonomy", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Taxonomy/TaxonomyFieldRepository.php#L27-L36
train
themosis/framework
src/Taxonomy/TaxonomyFieldRepository.php
TaxonomyFieldRepository.getFieldByName
public function getFieldByName(string $name) { $found = array_filter($this->fields, function ($field) use ($name) { /** @var FieldTypeInterface $field */ return $name === $field->getBaseName(); }); if (! empty($found)) { return array_pop($found); } throw new TaxonomyFieldNotFoundException("Taxonomy field with a name of {$name} not found."); }
php
public function getFieldByName(string $name) { $found = array_filter($this->fields, function ($field) use ($name) { /** @var FieldTypeInterface $field */ return $name === $field->getBaseName(); }); if (! empty($found)) { return array_pop($found); } throw new TaxonomyFieldNotFoundException("Taxonomy field with a name of {$name} not found."); }
[ "public", "function", "getFieldByName", "(", "string", "$", "name", ")", "{", "$", "found", "=", "array_filter", "(", "$", "this", "->", "fields", ",", "function", "(", "$", "field", ")", "use", "(", "$", "name", ")", "{", "/** @var FieldTypeInterface $field */", "return", "$", "name", "===", "$", "field", "->", "getBaseName", "(", ")", ";", "}", ")", ";", "if", "(", "!", "empty", "(", "$", "found", ")", ")", "{", "return", "array_pop", "(", "$", "found", ")", ";", "}", "throw", "new", "TaxonomyFieldNotFoundException", "(", "\"Taxonomy field with a name of {$name} not found.\"", ")", ";", "}" ]
Return a field instance by name. @param string $name @throws TaxonomyFieldNotFoundException @return FieldTypeInterface
[ "Return", "a", "field", "instance", "by", "name", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Taxonomy/TaxonomyFieldRepository.php#L57-L69
train
themosis/framework
src/View/Extensions/WordPress.php
WordPress.getFilters
public function getFilters() { return [ /** * Formatting filters. */ new \Twig_Filter('wpantispam', function ($email, $encoding = 0) { return antispambot($email, $encoding); }), new \Twig_Filter('wpautop', function ($text, $br = true) { return wpautop($text, $br); }), new \Twig_Filter('wpnofollow', function ($text) { return wp_rel_nofollow($text); }), new \Twig_Filter('wptrimexcerpt', function ($text) { return wp_trim_excerpt($text); }), new \Twig_Filter('wptrimwords', function ($text, $num_words = 55, $more = null) { return wp_trim_words($text, $num_words, $more); }), new \Twig_Filter('zeroise', function ($number, $treshold = 4) { return zeroise($number, $treshold); }) ]; }
php
public function getFilters() { return [ /** * Formatting filters. */ new \Twig_Filter('wpantispam', function ($email, $encoding = 0) { return antispambot($email, $encoding); }), new \Twig_Filter('wpautop', function ($text, $br = true) { return wpautop($text, $br); }), new \Twig_Filter('wpnofollow', function ($text) { return wp_rel_nofollow($text); }), new \Twig_Filter('wptrimexcerpt', function ($text) { return wp_trim_excerpt($text); }), new \Twig_Filter('wptrimwords', function ($text, $num_words = 55, $more = null) { return wp_trim_words($text, $num_words, $more); }), new \Twig_Filter('zeroise', function ($number, $treshold = 4) { return zeroise($number, $treshold); }) ]; }
[ "public", "function", "getFilters", "(", ")", "{", "return", "[", "/**\n * Formatting filters.\n */", "new", "\\", "Twig_Filter", "(", "'wpantispam'", ",", "function", "(", "$", "email", ",", "$", "encoding", "=", "0", ")", "{", "return", "antispambot", "(", "$", "email", ",", "$", "encoding", ")", ";", "}", ")", ",", "new", "\\", "Twig_Filter", "(", "'wpautop'", ",", "function", "(", "$", "text", ",", "$", "br", "=", "true", ")", "{", "return", "wpautop", "(", "$", "text", ",", "$", "br", ")", ";", "}", ")", ",", "new", "\\", "Twig_Filter", "(", "'wpnofollow'", ",", "function", "(", "$", "text", ")", "{", "return", "wp_rel_nofollow", "(", "$", "text", ")", ";", "}", ")", ",", "new", "\\", "Twig_Filter", "(", "'wptrimexcerpt'", ",", "function", "(", "$", "text", ")", "{", "return", "wp_trim_excerpt", "(", "$", "text", ")", ";", "}", ")", ",", "new", "\\", "Twig_Filter", "(", "'wptrimwords'", ",", "function", "(", "$", "text", ",", "$", "num_words", "=", "55", ",", "$", "more", "=", "null", ")", "{", "return", "wp_trim_words", "(", "$", "text", ",", "$", "num_words", ",", "$", "more", ")", ";", "}", ")", ",", "new", "\\", "Twig_Filter", "(", "'zeroise'", ",", "function", "(", "$", "number", ",", "$", "treshold", "=", "4", ")", "{", "return", "zeroise", "(", "$", "number", ",", "$", "treshold", ")", ";", "}", ")", "]", ";", "}" ]
Register a list of WordPress filters for use inside Twig templates. @return array|\Twig_Filter[]
[ "Register", "a", "list", "of", "WordPress", "filters", "for", "use", "inside", "Twig", "templates", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/View/Extensions/WordPress.php#L114-L139
train
themosis/framework
src/Route/Middleware/WordPressBodyClass.php
WordPressBodyClass.dispatchBodyClass
protected function dispatchBodyClass(Route $route) { return function ($classes) use ($route) { if ($route->hasCondition()) { return $classes; } $tokens = array_filter(array_map(function ($token) use ($route) { switch ($type = $token[0]) { case 'variable': if (isset($token[3]) && $route->hasParameter($paramKey = $token[3])) { $param = $route->parameter($paramKey); return is_string($param) ? sprintf('%s-%s', $paramKey, sanitize_title($param)) : false; } return false; break; case 'text': return sanitize_title($token[1]); break; default: return false; } }, array_reverse($route->getCompiled()->getTokens()))); if (! empty($tokens)) { return array_filter(array_merge($tokens, $classes), function ($class) { return 'error404' !== $class; }); } return $classes; }; }
php
protected function dispatchBodyClass(Route $route) { return function ($classes) use ($route) { if ($route->hasCondition()) { return $classes; } $tokens = array_filter(array_map(function ($token) use ($route) { switch ($type = $token[0]) { case 'variable': if (isset($token[3]) && $route->hasParameter($paramKey = $token[3])) { $param = $route->parameter($paramKey); return is_string($param) ? sprintf('%s-%s', $paramKey, sanitize_title($param)) : false; } return false; break; case 'text': return sanitize_title($token[1]); break; default: return false; } }, array_reverse($route->getCompiled()->getTokens()))); if (! empty($tokens)) { return array_filter(array_merge($tokens, $classes), function ($class) { return 'error404' !== $class; }); } return $classes; }; }
[ "protected", "function", "dispatchBodyClass", "(", "Route", "$", "route", ")", "{", "return", "function", "(", "$", "classes", ")", "use", "(", "$", "route", ")", "{", "if", "(", "$", "route", "->", "hasCondition", "(", ")", ")", "{", "return", "$", "classes", ";", "}", "$", "tokens", "=", "array_filter", "(", "array_map", "(", "function", "(", "$", "token", ")", "use", "(", "$", "route", ")", "{", "switch", "(", "$", "type", "=", "$", "token", "[", "0", "]", ")", "{", "case", "'variable'", ":", "if", "(", "isset", "(", "$", "token", "[", "3", "]", ")", "&&", "$", "route", "->", "hasParameter", "(", "$", "paramKey", "=", "$", "token", "[", "3", "]", ")", ")", "{", "$", "param", "=", "$", "route", "->", "parameter", "(", "$", "paramKey", ")", ";", "return", "is_string", "(", "$", "param", ")", "?", "sprintf", "(", "'%s-%s'", ",", "$", "paramKey", ",", "sanitize_title", "(", "$", "param", ")", ")", ":", "false", ";", "}", "return", "false", ";", "break", ";", "case", "'text'", ":", "return", "sanitize_title", "(", "$", "token", "[", "1", "]", ")", ";", "break", ";", "default", ":", "return", "false", ";", "}", "}", ",", "array_reverse", "(", "$", "route", "->", "getCompiled", "(", ")", "->", "getTokens", "(", ")", ")", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "tokens", ")", ")", "{", "return", "array_filter", "(", "array_merge", "(", "$", "tokens", ",", "$", "classes", ")", ",", "function", "(", "$", "class", ")", "{", "return", "'error404'", "!==", "$", "class", ";", "}", ")", ";", "}", "return", "$", "classes", ";", "}", ";", "}" ]
Return the callback managing route body CSS classes. @param Route $route @return \Closure
[ "Return", "the", "callback", "managing", "route", "body", "CSS", "classes", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Route/Middleware/WordPressBodyClass.php#L45-L79
train
themosis/framework
src/Core/Console/VendorPublishCommand.php
VendorPublishCommand.parseChoice
protected function parseChoice($choice) { list($type, $value) = explode(': ', strip_tags($choice)); if ($type === 'Provider') { $this->provider = $value; } elseif ($type === 'Tag') { $this->tags = [$value]; } }
php
protected function parseChoice($choice) { list($type, $value) = explode(': ', strip_tags($choice)); if ($type === 'Provider') { $this->provider = $value; } elseif ($type === 'Tag') { $this->tags = [$value]; } }
[ "protected", "function", "parseChoice", "(", "$", "choice", ")", "{", "list", "(", "$", "type", ",", "$", "value", ")", "=", "explode", "(", "': '", ",", "strip_tags", "(", "$", "choice", ")", ")", ";", "if", "(", "$", "type", "===", "'Provider'", ")", "{", "$", "this", "->", "provider", "=", "$", "value", ";", "}", "elseif", "(", "$", "type", "===", "'Tag'", ")", "{", "$", "this", "->", "tags", "=", "[", "$", "value", "]", ";", "}", "}" ]
Parse the answer that was given via the prompt. @param string $choice
[ "Parse", "the", "answer", "that", "was", "given", "via", "the", "prompt", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Console/VendorPublishCommand.php#L122-L131
train
themosis/framework
src/Core/Theme/Support.php
Support.parse
protected function parse(array $features) { $allowed = []; foreach ($features as $feature => $value) { if (is_int($feature)) { // Allow theme features without options. // Though post formats must be added with properties. // Here we first check that "post-formats" is not provided // without a value. If so, just pass it. if (! in_array($value, $this->mustHaveProperties, true)) { $allowed[$value] = $value; } else { throw new \InvalidArgumentException( 'The theme feature ['.$value.'] must have a defined property in order to work.' ); } } else { $allowed[$feature] = $value; } } return $allowed; }
php
protected function parse(array $features) { $allowed = []; foreach ($features as $feature => $value) { if (is_int($feature)) { // Allow theme features without options. // Though post formats must be added with properties. // Here we first check that "post-formats" is not provided // without a value. If so, just pass it. if (! in_array($value, $this->mustHaveProperties, true)) { $allowed[$value] = $value; } else { throw new \InvalidArgumentException( 'The theme feature ['.$value.'] must have a defined property in order to work.' ); } } else { $allowed[$feature] = $value; } } return $allowed; }
[ "protected", "function", "parse", "(", "array", "$", "features", ")", "{", "$", "allowed", "=", "[", "]", ";", "foreach", "(", "$", "features", "as", "$", "feature", "=>", "$", "value", ")", "{", "if", "(", "is_int", "(", "$", "feature", ")", ")", "{", "// Allow theme features without options.", "// Though post formats must be added with properties.", "// Here we first check that \"post-formats\" is not provided", "// without a value. If so, just pass it.", "if", "(", "!", "in_array", "(", "$", "value", ",", "$", "this", "->", "mustHaveProperties", ",", "true", ")", ")", "{", "$", "allowed", "[", "$", "value", "]", "=", "$", "value", ";", "}", "else", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The theme feature ['", ".", "$", "value", ".", "'] must have a defined property in order to work.'", ")", ";", "}", "}", "else", "{", "$", "allowed", "[", "$", "feature", "]", "=", "$", "value", ";", "}", "}", "return", "$", "allowed", ";", "}" ]
Parse theme features. @param array $features @return array
[ "Parse", "theme", "features", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Theme/Support.php#L36-L59
train
themosis/framework
src/Core/Theme/Support.php
Support.register
public function register() { if (! function_exists('add_theme_support') || empty($this->features)) { return; } foreach ($this->features as $feature => $value) { add_theme_support($feature, $value); } }
php
public function register() { if (! function_exists('add_theme_support') || empty($this->features)) { return; } foreach ($this->features as $feature => $value) { add_theme_support($feature, $value); } }
[ "public", "function", "register", "(", ")", "{", "if", "(", "!", "function_exists", "(", "'add_theme_support'", ")", "||", "empty", "(", "$", "this", "->", "features", ")", ")", "{", "return", ";", "}", "foreach", "(", "$", "this", "->", "features", "as", "$", "feature", "=>", "$", "value", ")", "{", "add_theme_support", "(", "$", "feature", ",", "$", "value", ")", ";", "}", "}" ]
Register theme support.
[ "Register", "theme", "support", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Core/Theme/Support.php#L64-L73
train
themosis/framework
src/Forms/Resources/Transformers/FieldTransformer.php
FieldTransformer.transform
public function transform(FieldTypeInterface $field) { return [ 'attributes' => $field->getAttributes(), 'basename' => $field->getBaseName(), 'component' => $field->getComponent(), 'data_type' => $field->getOption('data_type', ''), 'default' => $field->getOption('data', ''), 'name' => $field->getName(), 'options' => $this->getOptions($field), 'label' => [ 'inner' => $field->getOption('label'), 'attributes' => $field->getOption('label_attr', []) ], 'theme' => $field->getTheme(), 'type' => $field->getType(), 'validation' => [ 'errors' => $field->getOption('errors', true), 'messages' => $field->errors()->toArray(), 'placeholder' => $field->getOption('placeholder'), 'rules' => $field->getOption('rules', '') ], 'value' => 'checkbox' === $field->getType() ? $field->getRawValue() : $field->getValue(''), ]; }
php
public function transform(FieldTypeInterface $field) { return [ 'attributes' => $field->getAttributes(), 'basename' => $field->getBaseName(), 'component' => $field->getComponent(), 'data_type' => $field->getOption('data_type', ''), 'default' => $field->getOption('data', ''), 'name' => $field->getName(), 'options' => $this->getOptions($field), 'label' => [ 'inner' => $field->getOption('label'), 'attributes' => $field->getOption('label_attr', []) ], 'theme' => $field->getTheme(), 'type' => $field->getType(), 'validation' => [ 'errors' => $field->getOption('errors', true), 'messages' => $field->errors()->toArray(), 'placeholder' => $field->getOption('placeholder'), 'rules' => $field->getOption('rules', '') ], 'value' => 'checkbox' === $field->getType() ? $field->getRawValue() : $field->getValue(''), ]; }
[ "public", "function", "transform", "(", "FieldTypeInterface", "$", "field", ")", "{", "return", "[", "'attributes'", "=>", "$", "field", "->", "getAttributes", "(", ")", ",", "'basename'", "=>", "$", "field", "->", "getBaseName", "(", ")", ",", "'component'", "=>", "$", "field", "->", "getComponent", "(", ")", ",", "'data_type'", "=>", "$", "field", "->", "getOption", "(", "'data_type'", ",", "''", ")", ",", "'default'", "=>", "$", "field", "->", "getOption", "(", "'data'", ",", "''", ")", ",", "'name'", "=>", "$", "field", "->", "getName", "(", ")", ",", "'options'", "=>", "$", "this", "->", "getOptions", "(", "$", "field", ")", ",", "'label'", "=>", "[", "'inner'", "=>", "$", "field", "->", "getOption", "(", "'label'", ")", ",", "'attributes'", "=>", "$", "field", "->", "getOption", "(", "'label_attr'", ",", "[", "]", ")", "]", ",", "'theme'", "=>", "$", "field", "->", "getTheme", "(", ")", ",", "'type'", "=>", "$", "field", "->", "getType", "(", ")", ",", "'validation'", "=>", "[", "'errors'", "=>", "$", "field", "->", "getOption", "(", "'errors'", ",", "true", ")", ",", "'messages'", "=>", "$", "field", "->", "errors", "(", ")", "->", "toArray", "(", ")", ",", "'placeholder'", "=>", "$", "field", "->", "getOption", "(", "'placeholder'", ")", ",", "'rules'", "=>", "$", "field", "->", "getOption", "(", "'rules'", ",", "''", ")", "]", ",", "'value'", "=>", "'checkbox'", "===", "$", "field", "->", "getType", "(", ")", "?", "$", "field", "->", "getRawValue", "(", ")", ":", "$", "field", "->", "getValue", "(", "''", ")", ",", "]", ";", "}" ]
Transform single field. @param FieldTypeInterface $field @return array
[ "Transform", "single", "field", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/Resources/Transformers/FieldTransformer.php#L36-L60
train
themosis/framework
src/Forms/Resources/Transformers/CollectionFieldTransformer.php
CollectionFieldTransformer.getOptions
protected function getOptions(FieldTypeInterface $field) { $options = parent::getOptions($field); $options['items'] = array_map(function ($id) { return [ 'attributes' => wp_prepare_attachment_for_js($id), 'id' => $id ]; }, (array) $field->getValue()); return $options; }
php
protected function getOptions(FieldTypeInterface $field) { $options = parent::getOptions($field); $options['items'] = array_map(function ($id) { return [ 'attributes' => wp_prepare_attachment_for_js($id), 'id' => $id ]; }, (array) $field->getValue()); return $options; }
[ "protected", "function", "getOptions", "(", "FieldTypeInterface", "$", "field", ")", "{", "$", "options", "=", "parent", "::", "getOptions", "(", "$", "field", ")", ";", "$", "options", "[", "'items'", "]", "=", "array_map", "(", "function", "(", "$", "id", ")", "{", "return", "[", "'attributes'", "=>", "wp_prepare_attachment_for_js", "(", "$", "id", ")", ",", "'id'", "=>", "$", "id", "]", ";", "}", ",", "(", "array", ")", "$", "field", "->", "getValue", "(", ")", ")", ";", "return", "$", "options", ";", "}" ]
Transform field options. @param FieldTypeInterface $field @return array
[ "Transform", "field", "options", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/Resources/Transformers/CollectionFieldTransformer.php#L16-L28
train
themosis/framework
src/Forms/Form.php
Form.setPrefix
public function setPrefix(string $prefix): FieldTypeInterface { $this->prefix = $prefix; // Update all attached fields with the given prefix. foreach ($this->repository->all() as $field) { /** @var FieldTypeInterface $field */ $field->setPrefix($prefix); } return $this; }
php
public function setPrefix(string $prefix): FieldTypeInterface { $this->prefix = $prefix; // Update all attached fields with the given prefix. foreach ($this->repository->all() as $field) { /** @var FieldTypeInterface $field */ $field->setPrefix($prefix); } return $this; }
[ "public", "function", "setPrefix", "(", "string", "$", "prefix", ")", ":", "FieldTypeInterface", "{", "$", "this", "->", "prefix", "=", "$", "prefix", ";", "// Update all attached fields with the given prefix.", "foreach", "(", "$", "this", "->", "repository", "->", "all", "(", ")", "as", "$", "field", ")", "{", "/** @var FieldTypeInterface $field */", "$", "field", "->", "setPrefix", "(", "$", "prefix", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set the form prefix. If fields are attached to the form, all fields are updated with the given prefix. @param string $prefix @return FieldTypeInterface
[ "Set", "the", "form", "prefix", ".", "If", "fields", "are", "attached", "to", "the", "form", "all", "fields", "are", "updated", "with", "the", "given", "prefix", "." ]
9931cdda709b94cc712495acf93211b6fa9d23a7
https://github.com/themosis/framework/blob/9931cdda709b94cc712495acf93211b6fa9d23a7/src/Forms/Form.php#L214-L225
train