Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #61: Publish/Unpublish option for Paragraphs #96

Merged
merged 10 commits into from
Oct 18, 2021
Merged
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
27 changes: 27 additions & 0 deletions ParagraphsItemEntity.inc
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ class ParagraphsItemEntity extends Entity {
*/
public $revision_id;

/**
* Whether the paragraphs item is published.
*
* @var bool
*/
public $status = TRUE;

/**
* The name of the paragraphs field this item is associated with.
*
Expand Down Expand Up @@ -176,6 +183,26 @@ class ParagraphsItemEntity extends Entity {
);
}

/**
* Overrides Entity::access().
*
* @param string $op
* The operation to be performed on the node. Possible values are:
* - create
* - view
* - update
* - delete
* @param User|AnonymousUser|object $account
* (optional) The user to check for. Leave it to NULL to check for the
* global user.
*
* @return bool|NULL
* TRUE if access is granted, FALSE otherwise.
*/
public function access($op, $account = NULL) {
return paragraphs_item_access($op, $this, $account);
}

/**
* Sets the host entity. Only possible during creation of a item.
*
Expand Down
27 changes: 19 additions & 8 deletions css/paragraphs.css
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
.paragraphs-icon {
max-height: 50px;
.field-widget-paragraphs-embed .removed {
padding-left: 1.5rem;
background: repeating-linear-gradient(
45deg,
rgba(231,37,27,.07),
rgba(231,37,27,.07) 20px,
rgba(231,37,27,.1) 20px,
rgba(231,37,27,.1) 40px
);
}

.paragraphs-label {
font-weight: bold;
.field-widget-paragraphs-embed .unpublished {
padding-left: 1.5rem;
color: #444;
background: repeating-linear-gradient(
45deg,
rgba(0,0,0,.05),
rgba(0,0,0,.05) 20px,
rgba(0,0,0,.03) 20px,
rgba(0,0,0,.03) 40px
);
}
.paragraphs-machine-name {
font-size: smaller;
}
1 change: 1 addition & 0 deletions migrate/destinations/MigrateDestinationParagraphsItem.inc
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ class MigrateDestinationParagraphsItem extends MigrateDestinationEntity {
'bundle' => $this->bundle,
'field_name' => $this->field_name,
'archived' => 0,
'status' => 1,
);
foreach ($defaults as $field => $value) {
if (!isset($paragraphs_item->$field)) {
Expand Down
9 changes: 9 additions & 0 deletions paragraphs.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ function paragraphs_admin_bundle_form(array $form, array &$form_state, $bundle =
$bundle->label = '';
$bundle->description = '';
$bundle->locked = 0;
$bundle->allow_unpublish = 1;
}
else {
if (!$bundle) {
Expand Down Expand Up @@ -156,6 +157,12 @@ function paragraphs_admin_bundle_form(array $form, array &$form_state, $bundle =
'#value' => $bundle->locked,
);

$form['allow_unpublish'] = array(
'#type' => 'checkbox',
'#title' => t('Allow unpublishing from the admin interface.'),
'#default_value' => (isset($bundle->allow_unpublish)) ? $bundle->allow_unpublish : 0,
);

$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
Expand Down Expand Up @@ -216,6 +223,8 @@ function paragraphs_admin_bundle_form_submit(array $form, array &$form_state) {

$bundle->name = trim($form_state['values']['name']);

$bundle->allow_unpublish = $form_state['values']['allow_unpublish'];

// Set bundle label equal to name if empty.
$bundle->label = empty($form_state['values']['label']) ? $bundle->name : trim($form_state['values']['label']);

Expand Down
Loading