Skip to content

Commit

Permalink
Merge pull request Gizra#79 from mradcliffe/fix-og-audience-field
Browse files Browse the repository at this point in the history
Change remaining OG_AUDIENCE_FIELD constants in og_ui to class constant.
  • Loading branch information
amitaibu committed Dec 7, 2015
2 parents 8577ee5 + 8336181 commit 91ac0e1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ provide a quick way to get started with Organic groups.
\Drupal\og\Og::groupManager()->addGroup('node', 'page');

// Add og audience field to "Article" node type, thus making is a group content.
\Drupal\og\Og::createField(\Drupal\og\OgAudienceFieldHelper::DEFAULT_FIELD, 'node', 'article');
\Drupal\og\Og::createField(\Drupal\og\OgGroupAudienceHelper::DEFAULT_FIELD, 'node', 'article');
```

## FAQ
Expand Down
7 changes: 4 additions & 3 deletions og_ui/og_ui.module
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\og\Og;
use Drupal\og\OgGroupAudienceHelper;
use Drupal\og_ui\BundleFormAlter;

/**
Expand Down Expand Up @@ -65,16 +66,16 @@ function og_ui_entity_type_save(EntityInterface $entity) {
$is_group_content = Og::isGroupContent($entity_type_id, $bundle);
if ($entity->og_group_content_bundle != $is_group_content) {
if ($entity->og_group_content_bundle) {
Og::createField(OG_AUDIENCE_FIELD, $entity_type_id, $bundle);
Og::createField(OgGroupAudienceHelper::DEFAULT_FIELD, $entity_type_id, $bundle);
}
elseif ($field = FieldConfig::loadByName($entity_type_id, $bundle, OG_AUDIENCE_FIELD)) {
elseif ($field = FieldConfig::loadByName($entity_type_id, $bundle, OgGroupAudienceHelper::DEFAULT_FIELD)) {
$field->delete();
return;
}
}

// Change the field target type and bundle.
if ($field = FieldConfig::loadByName($entity_type_id, $bundle, OG_AUDIENCE_FIELD)) {
if ($field = FieldConfig::loadByName($entity_type_id, $bundle, OgGroupAudienceHelper::DEFAULT_FIELD)) {
$handler_settings = $field->getSetting('handler_settings');
$save = FALSE;
foreach (['target_type', 'target_bundles'] as $key) {
Expand Down
3 changes: 2 additions & 1 deletion og_ui/src/BundleFormAlter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Drupal\Core\Form\FormStateInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\og\Og;
use Drupal\og\OgGroupAudienceHelper;

/**
* Helper for og_ui_form_alter().
Expand Down Expand Up @@ -112,7 +113,7 @@ protected function addGroupContent(array &$form, $form_state) {

$target_type_default = FALSE;
$handler_settings = [];
if ($field = FieldConfig::loadByName($this->entityTypeId, $this->bundle, OG_AUDIENCE_FIELD)) {
if ($field = FieldConfig::loadByName($this->entityTypeId, $this->bundle, OgGroupAudienceHelper::DEFAULT_FIELD)) {
$handler_settings = $field->getSetting('handler_settings');
if (isset($handler_settings['target_type'])) {
$target_type_default = $handler_settings['target_type'];
Expand Down

0 comments on commit 91ac0e1

Please sign in to comment.