Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Console/OptionsMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class OptionsMakeCommand extends MakeCommand
*/
protected $signature = 'acf:options {name* : The name of the options page}
{--full : Scaffold an options page that contains the complete configuration.}
{--localize : Localize the options page name and title}
{--force : Overwrite any existing files}';

/**
Expand Down Expand Up @@ -45,6 +46,10 @@ protected function getStub()
return $this->resolveStub('options.full');
}

if ($this->option('localize')) {
return $this->resolveStub('options.localized');
}

return $this->resolveStub('options');
}
}
1 change: 1 addition & 0 deletions src/Console/StubPublishCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class StubPublishCommand extends Command
'block.localized.stub',
'block.stub',
'field.stub',
'options.localized.stub',
'options.full.stub',
'options.stub',
'partial.stub',
Expand Down
47 changes: 47 additions & 0 deletions src/Console/stubs/options.localized.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace DummyNamespace;

use Log1x\AcfComposer\Builder;
use Log1x\AcfComposer\Options as Field;

class DummyClass extends Field
{
/**
* Retrieve the option page menu name.
*/
public function getName(): string
{
return __('DummyTitle', 'sage');
}

/**
* Retrieve the option page document title.
*/
public function getTitle(): string
{
return __('DummyTitle', 'sage');
}

/**
* The option page menu position.
*
* @var int
*/
public $position = PHP_INT_MAX;

/**
* The option page field group.
*/
public function fields(): array
{
$fields = Builder::make('DummySnake');

$fields
->addRepeater('items')
->addText('item')
->endRepeater();

return $fields->build();
}
}
7 changes: 7 additions & 0 deletions src/Console/stubs/options.stub
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ class DummyClass extends Field
*/
public $title = 'DummyTitle | Options';

/**
* The option page menu position.
*
* @var int
*/
public $position = PHP_INT_MAX;

/**
* The option page field group.
*/
Expand Down
32 changes: 24 additions & 8 deletions src/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,22 @@ abstract class Options extends Composer
*/
public $settings = [];

/**
* Retrieve the option page menu name.
*/
public function getName(): string
{
return $this->name;
}

/**
* Retrieve the option page document title.
*/
public function getTitle(): string
{
return $this->title;
}

/**
* Localized text displayed on the submit button.
*
Expand Down Expand Up @@ -118,16 +134,16 @@ public function updatedMessage()
*/
public function compose()
{
if (empty($this->name)) {
return;
}
if (blank($this->getName())) {
return null;
}

if (empty($this->slug)) {
$this->slug = Str::slug($this->name);
$this->slug = Str::slug($this->getName());
}

if (empty($this->title)) {
$this->title = $this->name;
if (blank($this->getTitle())) {
$this->title = $this->getName();
}

if (! Arr::has($this->fields, 'location.0.0')) {
Expand All @@ -145,9 +161,9 @@ public function compose()

acf_add_options_page(
array_merge([
'menu_title' => $this->name,
'menu_title' => $this->getName(),
'menu_slug' => $this->slug,
'page_title' => $this->title,
'page_title' => $this->getTitle(),
'capability' => $this->capability,
'position' => $this->position,
'parent_slug' => $this->parent,
Expand Down
Loading