-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
185 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace ColdTrick\BlogTools; | ||
|
||
use Elgg\Blog\Forms\PrepareFields; | ||
|
||
/** | ||
* Handle blog form fields | ||
*/ | ||
class FieldsHandler { | ||
|
||
/** | ||
* Change fields for blogs | ||
* | ||
* @param \Elgg\Event $event 'fields', 'object:blog' | ||
* | ||
* @return null|array | ||
*/ | ||
public function __invoke(\Elgg\Event $event): ?array { | ||
$result = $event->getValue(); | ||
|
||
foreach ($result as $field) { | ||
if (elgg_extract('name', $field) !== 'access_id') { | ||
continue; | ||
} | ||
|
||
if (elgg_get_plugin_setting('advanced_publication', 'blog_tools') === 'yes') { | ||
$field['#help'] = elgg_echo('blog_tools:edit:access:help:publication'); | ||
} else { | ||
$field['#help'] = elgg_echo('blog_tools:edit:access:help'); | ||
} | ||
|
||
break; | ||
} | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace ColdTrick\BlogTools\Forms; | ||
|
||
/** | ||
* Prepare the fields for the blog/save form | ||
*/ | ||
class PrepareFields { | ||
|
||
/** | ||
* Prepare the advanced publication options | ||
* | ||
* @param \Elgg\Event $event 'form:prepare:fields', 'blog/save' | ||
* | ||
* @return null|array | ||
*/ | ||
public function __invoke(\Elgg\Event $event): ?array { | ||
if (elgg_get_plugin_setting('advanced_publication', 'blog_tools') !== 'yes') { | ||
return null; | ||
} | ||
|
||
$vars = $event->getValue(); | ||
|
||
$values = [ | ||
'publication_date' => null, | ||
'publication_time' => null, | ||
]; | ||
|
||
$entity = elgg_extract('entity', $vars); | ||
if ($entity instanceof \ElggBlog) { | ||
// load current blog values | ||
foreach (array_keys($values) as $field) { | ||
$metadata_name = $field; | ||
if ($field === 'publication_time') { | ||
$metadata_name = 'publication'; | ||
} | ||
|
||
if (!isset($entity->{$metadata_name})) { | ||
continue; | ||
} | ||
|
||
$values[$field] = $entity->{$metadata_name}; | ||
} | ||
} | ||
|
||
return array_merge($values, $vars); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.