PHP code example of steirico / kirby-plugin-custom-add-fields

1. Go to this page and download the library: Download steirico/kirby-plugin-custom-add-fields library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

steirico / kirby-plugin-custom-add-fields example snippets


> 
> class RemotePage extends Page {
>     public static function hookPageCreate($page){
>         // get value of add field remoteUrl
>         $remoteUrl = $page->remoteUrl()->value();
>
>         // fetch remote content
>         $content = file_get_contents($remoteUrl);
>
>         // update page field content
>         $page->update(array(
>             'content' => $content
>         ));
>
>         // set slug according to add field title
>         $page->changeSlug(Str::slug($page->title()->value()));
>     }
> }
>

> try {
>     // set slug according to add field title
>     $page->changeSlug(Str::slug($page->title()->value()));
> } catch (Kirby\Exception\DuplicateException $e) {
>     // A pages withe the same slug already exists.
>     // Therefore, delete the newly created one.
>     $page->delete(true);
> }
>

> 
>
> return [
>     // exitsing configurations
>     'steirico.kirby-plugin-custom-add-fields.forcedTemplate.fieldName' => 'myForcedTemplateField'
> ];
>

> 
>
> return [
>     // exitsing configurations
>     'steirico.kirby-plugin-custom-add-fields.forceTemplateSelectionField' => true
> ];
>

  'bnomei.securityheaders.enabled' => function () {
    # Panel check, borrowed from @bnomei's `security-headers`
    # See https://github.com/bnomei/kirby3-security-headers/issues/18#issuecomment-709985170
    $isPanel = strpos(
        kirby()->request()->url()->toString(),
        kirby()->urls()->panel
    ) !== false;

    if ($isPanel) {
        return false;
    }

    return true; // or 'force'
  }
  
yaml
>   title: Parent Blueprint which skips the Add Dialog
>
>   # custom add fields definition
>   addFields:
>       __dialog:
>           redirect: true
>   
yaml
>   title: Parent Blueprint which skips the Add Dialog
>
>   # custom add fields definition
>   addFields:
>       __dialog:
>           skip: true
>           forcedTemplate: remote
>